Skip to content
Advertisement

Tag: mysql

How To use multiple columns

I’m trying to get a result : does not work for me, any help Answer You can use GROUP_CONCAT for that purpose day | kine | color –: | :—- | :—————– 1 | 1,2 | white,orange 2 | 1,2,3 | White,Orange,White db<>fiddle here

Pick the max value of id from multiple tables

I have 3 tables. Each of them have id column as PRIMARY. There is no relation between tables. I want to make a query which gives me the max id of every table. What I have tried was this: But I get NULL, NULL, NULL. It is possible to done that? If yes, how? Answer MySQL syntax supports placing subqueries

MySQL: Return a row if all joint table row have the value true

I’ve two tables as following. The relationship is What I want is to return for example for table A the record with id 1 which has a relationship with table B where all the values on table B column Delivered as true. Answer You can use group by and having: This doesn’t use table a. If you want all the

add auto generate column with correlated subqueries in mysql

I want to add a column that auto generates value depending on other tables. There are 2 tables to work with. Table “finance” : Table “price” : And by executing this command I get this result I wanted to make the revenue_x_10 auto generated by doing something like this. But looks like I can only put columns from the same

MYSQL in AWS Athena

Using AWS Athena (so querying with MySql) I’m trying to retrieve information how many times the same IP has been logged. I have columns: timestamp, IP, country. I would like to count unique occurrences of each IP. I’m trying with this query but results are wrong: Thank you for helping achieving me this counter query. EDIT: Sample data: Answer If

How do you use mysql to only return a record if no conflicts exist?

Is there a way to have a SELECT statement only return a result if there exist no records in the database that conflict with the conditions? For example, people can reserve a table for two-hour blocks. A new reservation should only be allowed if there are no reservations that overlap with the new request. Something like the following doesn’t work

How to read from the two same dates without input the time

I have a query like below. When I submit a date like the following patients.created_at BETWEEN ‘2018-05-22’ AND ‘2018-05-22’ it doesn’t return anything but if I enter BETWEEN ‘2018-05-22’ patients.created_at ‘AND’ 2018-05-23′ it returns a value. I think if I just input two of the same date without entering the time then the time will be 00:00:00 – 00:00:00. How

Consolidate SQL Union With JOIN

Let’s say I have 2 tables (bar_helper and bar). I have a query that retrieves records based on a JOIN between the tables and some condition. Essentially, my first result set is joined and I want my second one to be unconditional and just based on one table. This works fine. However, now I need to also get a second

Advertisement