How to select rows based on other tables - MySql I have tables like this:

CheckTable

(id) (user_id)
[0]  [403]


UserTable

(id)  (username)
[403] [hello]


I want to select only the rows from the UserTable that do not have the user id row in the CheckTable

I could just select all the users, loop through the rows and then run another query checking if the user_id is in the UserTable, but that would be slow.

Is there any MySQL query that could join and select.
Is this what you're looking for?

SELECT Whatever FROM UserTable
WHERE UserTable.username NOT IN 
(
  SELECT CheckTable.user_id FROM CheckTable
);


If this is not suitable, please expand. Possibly with table definitions - (SHOW CREATE TABLE My_Table\G) and some sample data - (INSERT INTO My_Table VALUES(....)), and finally, the result you want with the logic you used to obtain it.

With further research, you might also find this interesting - and also this. As a generic response, substituting NOT EXISTS for NOT IN might be the way to go - YMMV.