1

I am using php.

$sql = "UPDATE `table` SET `field` = 'value' WHERE `item_id` IN (comma separated list of item_ids)";

If I execute the above query, how can I find out which item_id's where updated? Note that some of the id's in the comma separated list of item_ids do not exist in the 'table' otherwise the answer would be trivially every id in the comma separated list.

I am using the mysql api where you connect via mysql_connect().

Hard worker
  • 3,916
  • 5
  • 44
  • 73
  • 1
    If you're only concerned to find which IDs exist, why not `SELECT item_id FROM \`table\` where item_id IN (...)`? – eggyal Feb 18 '13 at 11:56
  • 1
    You didn't specify which MySQL API you're using. – MrCode Feb 18 '13 at 11:56
  • True eggyal in this case, but I also have more complicated queries where that isn't the case. If I can find an answer to this query I could apply it to my other queries. – Hard worker Feb 18 '13 at 13:20
  • @MrCode I am just using a standard WAMP stack. I'm not sure what you mean by API I will investigate – Hard worker Feb 18 '13 at 13:20
  • @Hardworker there are several MySQL API's: `mysql_*`, MySQLi, PDO etc etc. – MrCode Feb 18 '13 at 13:21
  • You have taught my something new. I am using the msql api (where you connect via mysql_connect() ) – Hard worker Feb 18 '13 at 13:23
  • This will help you lost please visit [http://stackoverflow.com/questions/1388025/how-to-get-id-of-the-last-updated-row-in-mysql][1] [1]: http://stackoverflow.com/questions/1388025/how-to-get-id-of-the-last-updated-row-in-mysql – Elby Feb 18 '13 at 13:34

1 Answers1

-2

use mysql_affected_rows(). it will return the table's incremented id's array which are affected in the last query.

Ripa Saha
  • 2,532
  • 6
  • 27
  • 51