Skip to content

Tag: mysql

MySQL trigger not functioning correctly

I currently working my AWS RDS MySQL through R notebook. I have a table like this: With a trigger like this I could create table and trigger without problems; however, when I insert something like this The insertion was successful but I would get an instance of fruit with ‘C’, instead of ‘A&…

SQL query that returns the primary key if found, NULL otherwise

Given a table like I am looking for a query that searches for a given name, returns the id if found, and NULL otherwise. Sort of what left join can do, except here there is no left table. Answer Use aggregation with MAX() (or MIN()): An aggregation query like this always returns exactly 1 row with 1 column an…

How to construct SQL query to get the output as below

the below image is how the table related and the expected output result. I used MySQL version 6.3.3. and the below is currently can be achieved. and below is the SQL query code Anyone can help me to improvise the SQL query code above to get the expected output is very appreciated and thank you very much&#8230…

mysql single column condition query on a multi-column index

suppose a table has only one index : idx_goods (is_deleted,price) and is_deleted column is either 0 or 1 my query looks like this : where price < 10, which of the follwing behavior is this case: 1 mysql do a full scan on the secondary index for price match 2 mysql partially scan the secondary index for pri…

SQL Case Statement: Set the default value for an Case

this time I need an explanation for SQL. I have seen on the internet now nothing special and maybe I have a thinking error. I have a case statement and now I want to ” filter ” it in different ways. Specifically I have a question, whether it is possible to provide rows directly with the “ELS…

Select all ID’s that have overlapping timestamp values

Given this table, I’m trying to select all of ids that have an overlapping start_time and end_time grouped by ID. In this case, the table has multiple Ids that may or may not have multiple entries. (In this case, id’s 1 and 2 don’t have multiple rows, whereas 0 does.) Is there a way to retri…