opposite of insert into - removing duplicates

Viewed 496

I am very new to Sql, so bear with me. I have run a query the following query:

INSERT INTO adhoc_dt.`table` (id, name) VALUES(53098974, 'John');

however, by accident I run it twice. I would like to remove the duplicate. How can that be done?

I tried

 INSERT INTO adhoc_dt.`table` (id, name) VALUES(53098974, 'John');

but get an error:

SQL ERROR [1064][42000]: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near

2 Answers

If your table name include special char of reserved word then you should enclose the table name with backticks:

 `table`

But looking to your question, the table name seems:

`adhoc_dt.`table` 

In this case, the correct syntax for delete is:

DELETE FROM  adhoc_dt.`table`
WHERE id =  53098974 AND name =  'JOHN'

but in this way you delete all the rows with:

 id =  53098974 AND name =  'JOHN'

You have to follow steps

  • truncate table
  • apply unique constraint on ID
  • run insert script
Related