Table 1

id | name

1    alo
2    nemo 
5    gogo

Table 2

id | object

1    have
2    name
5    lok
4    fan

Things I am attempting to do is removing the row using the id=4 in table2 since it does not appear in table1 1.

How do i do this type of comparison, on database tables which have a lot more than 400.000 rows?

DELETE FROM table2
WHERE id NOT IN (SELECT id FROM table1)