bucko Posted February 29, 2008 Share Posted February 29, 2008 Hi, I have this situation in mySQL 'table1' has an 'id' field. 'table2' has a 'table1_id' field, same value as table1:id I have deleted some entries from 'table1' Now I want to delete all entries in 'table2' where there is no 'table_id' in 'table1:id' Can someone please tell me nice way to perform that request? Thanks in advance for any suggestions. bucko. Quote Link to comment Share on other sites More sharing options...
fri3ndly Posted February 29, 2008 Share Posted February 29, 2008 Hmm would it be something like DELETE FROM table2 WHERE table_id != 'id' Haven't tested it and dont know if that is valid SQL...give it a try though Quote Link to comment Share on other sites More sharing options...
drewbee Posted February 29, 2008 Share Posted February 29, 2008 This is psudo code, please backup your database before testing. DELETE FROM table2 WHERE table1_id NOT IN (SELECT id FROM table1) Note: REVERSE LOOKUPS (NOT IN) take a long time to execute if you have a lot of rows. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.