tags:

views:

1393

answers:

3

Is it possible to run an UPDATE command on mysql 5.0 with a sub select.

The command I would like to run is this:

UPDATE book_details
SET live = 1 
WHERE ISBN13 = '(SELECT ISBN13 FROM book_details_old WHERE live = 1)';

ISBN13 is currently stored as a string.

This should be updating 10k+ rows.

Thanks,

William

+3  A: 

UPDATE book_details AS bd, book_details_old AS old
SET bd.live=1
WHERE bd.isbn13=old.isbn13
AND old.live=1;

Rob
A: 

Yes it is possible. The discussion on this page should help.

Vincent Ramdhanie
+4  A: 

Just a litle change and you got it:

UPDATE book_details
SET live = 1 
WHERE ISBN13 in (SELECT ISBN13 FROM book_details_old WHERE live = 1);
Ricardo Acras