Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete multiple rows with 2 columns as composite primary key in MySQL?

My innodb table has the following structure: 4 columns (CountryID, Year, %Change, Source), with the 2 columns (CountryID, Year) as the primary key. How do I delete multiple rows other than using a for-loop to delete each row?

I'm looking for something similar to

DELETE FROM CPI   WHERE CountryID AND Year IN (('AD', 2010), ('AF', 2009), ('AG', 1992)) 
like image 787
Ana Ban Avatar asked Dec 04 '11 13:12

Ana Ban


1 Answers

The answer in Oracle is:

delete from cpi  where (countryid, year) in (('AD', 2010), ('AF', 2009), ('AG', 1992)) 

It's fairly standard SQL syntax and I think MySQL is the same.

like image 63
Ben Avatar answered Sep 26 '22 00:09

Ben