How to delete a certain row from mysql table with same column values?

Dani picture Dani · Aug 22, 2013 · Viewed 531.3k times · Source

I have a problem with my queries in MySQL. My table has 4 columns and it looks something like this:

id_users    id_product    quantity    date
 1              2              1       2013
 1              2              1       2013
 2              2              1       2013
 1              3              1       2013

id_users and id_product are foreign keys from different tables.

What I want is to delete just one row:

1     2     1    2013

Which appears twice, so I just want to delete it.

I've tried this query:

delete from orders where id_users = 1 and id_product = 2

But it will delete both of them (since they are duplicated). Any hints on solving this problem?

Answer

juergen d picture juergen d · Aug 22, 2013

Add a limit to the delete query

delete from orders 
where id_users = 1 and id_product = 2
limit 1