Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
235 views
in Technique[技术] by (71.8m points)

Update mysql table with data from another table

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

question from:https://stackoverflow.com/questions/414828/update-mysql-table-with-data-from-another-table

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
UPDATE table1 t1, table2 t2
SET t1.field_to_change = t2.field_with_data
WHERE t1.field1 = t2.field2;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...