Skip to content

Tag: mysql

MySQL Merge two queries based on mutual column

I have two queries that retrieve records from 2 different tables that are almost alike and I need to merge them together. Both have created_date which is of type datetime and I’m casting this column to date because I want to group and order them by date only, I don’t need the time. First query: Se…

MySQL – why limit varchar

In MySQL you have to set a limit if you are to use a varchar. Does this limit only exist to make it less likely for devs to accidentally store too much data or is there any other reason (i.e. more effcient access) to set it to a low value? Answer VARCHAR columns are represented in the database with a

mysql query error: SQL sum with condition

This is my code: select assignedstfid, staffname, staffsymbol, SUM(case where bookingstarttime > ‘2021-03-31’ then TIMESTAMPDIFF (minute, bookingstarttime, bookingendtime) else 0 end) as …

Interval to previous row

I would like to get the interval between the rows in my table. When I use this query I get seconds from previous timestamp. But the result is only right when two timestamps is in the same minute. …