There are several ways to do this. Here is one approach using NOT EXISTS :
SELECT userid FROM table1 WHERE NOT EXISTS ( SELECT * FROM table2 WHERE table1.userid = table2.userid )
And here is another approach using a join:
SELECT table1.userid FROM table1 LEFT JOIN table2 ON table1.userid = table2.userid WHERE table2.userid IS NULL
The fastest approach is database dependent.
source share