是否可以使用子选择在mysql 5.0上运行UPDATE命令。
我想要运行的命令是:
UPDATE book_details
SET live = 1
WHERE ISBN13 = '(SELECT ISBN13 FROM book_details_old WHERE live = 1)';
ISBN13目前存储为字符串。
这应该更新10k +行。
谢谢,
威廉
答案 0 :(得分:178)
UPDATE table1 t1, table2 t2
SET t1.field_to_change = t2.field_with_data
WHERE t1.field1 = t2.field2;
答案 1 :(得分:22)
UPDATE book_details AS bd, book_details_old AS old
SET bd.live=1
WHERE bd.isbn13=old.isbn13
AND old.live=1;
答案 2 :(得分:16)
只需稍加改动就可以了:
UPDATE book_details
SET live = 1
WHERE ISBN13 in (SELECT ISBN13 FROM book_details_old WHERE live = 1);
答案 3 :(得分:3)
从其他表格中的数据更新表格
UPDATE table1, table2 SET table1.field1 = table2.field1 where table1.id = table2.id
EX。UPDATE transaction, member SET transaction.Memberid = member.memberId
WHERE transaction.CardId = member.CardId;
答案 4 :(得分:-4)
从其他表格更新数据
UPDATE tab t1
SET t1.company_name = t2.company_name
FROM tab t2
WHERE t1.id = t2.id