Let I have two tables: Table one: have tow columns: id | name Table two: have tow columns: id | name_id I want to delete all records from 2nd table whose name_id is not present in table one's id column. Can anyone help me in this. Thanks in advance.
This should work for you. Always make sure you have a backup in case you do get some poor advice... DELETE FROM table_2 WHERE name_id NOT IN (SELECT id FROM table_1)
jestep's query will work for you - just a note to add: if you want to build in protection so this won't happen again you should add a FOREIGN KEY to table_2.