Skip to content

Mysql query for getting today’s data in a sub-query #mysql

I have to get today’s data in MySQL query. In this query, it shows the error message that we can select one column which is understandable as I have used (col1, col2(for date)) as col. but I need a solution to get this done. thanks Answer If you need today’s data only, You should use the condition…

How to get Postgres to return 0 for empty rows

I have a query which get data summarised between two dates like so: However for dates that do not have any orders, the query returns nothing and I’d like to return 0. I have tried with COALESCE but that doesn’t seem to do the trick? Any suggestions? Answer Please refer to the below script. There i…

SQL without triggers: one query for all the usecases

Having the following table: I have the following use cases (“oldInfo” field will always be set to zero): First time insert for the pair (field1, oldInfo). Second time insert for the pair (field1, oldInfo). The existing oldInfo field shall be set to one before the insertion of the new row due to th…

How to leave only distinct rows in the table. Postgresql

I need to delete all duplicate in 40kk of rows. I’ve got table: I’ve tried this query but after 1h of executing I’ve gave up on waiting. Is there any other solution to delete duplicates in more optimazed way? UPD: I need to do it just once cause I didn’t handle the duplicates at the st…