Skip to content

Tag: sql-delete

DELETE entry that is older than current datetime in MySQL

I have tried the following among various other statements but thought one of these should obviously work but no luck so far. Please tell me what I’m doing wrong. Not getting an error, it’s just not working. DELETE FROM table_name WHERE from < NOW() DELETE FROM table_name WHERE from < ‘2022-04-16 08:00:00’ Example Answer You shouldn’t name your columns (or

T-SQL :: TRUNCATE or DELETE all tables in schema

I need to TRUNCATE or DELETE all tables in schema. I found this code: but on AdventureWorks it gives me: So I found this alternative code: But the result is the same: How to TRUNCATE or DELETE all tables in schema? Answer You simply need to wrap your “delete from all the tables” script with a “drop all foreign keys”

Delete all duplicates except first one mysql

I have a table with a column serial_number that is repeated a few times. How would I delete the entire row except the first duplicate? By the following, I can select all the duplicates. But can’t delete. SELECT serial_number, COUNT(*) FROM trademark_merge GROUP BY serial_number HAVING COUNT(*) > 1 Answer Assuming that the primary key of your table is id,