I have 2 tables: tb1 and tb2. Table tb1 has fields id1 and id2. Table tb2 has field id2. 'id2' is the same on both tables. Now, with only know id1, how to delete a record in tb2?
Oh, forgot to say, I wouldn't want to make more than 1 sql statement such thing as select for id2 first... Please help. Thanks.
Greetings. Here's a MySQL example:
DELETE FROM tb2 USING tb1,tb2 WHERE tb1.id2=tb2.id2
Note: I got this from
http://www.mysql.com/doc/D/E/DELETE.html
which has notes on the version applicability of this form of the DELETE command - YMMV.
Good luck,
-drsteve
Yep, it looks right but didn't work for me. It showed syntax error on "USING..". What version is it for? Mine is 3.23.47. This is weird.
It's either 4.0.0+, or 4.0.2+, depending on which version of the command you use (the web pages gives two for referencing multiple tables at once). You may be out of luck unless you upgrade 🙂