MySQL - query All users WITHOUT assignment

If I have two tables: "Users and Appointments". How would I query the db to find something like the following:

SELECT * FROM users WHERE (none of: appointments.user = user.id)

      

I'm guessing I'll need some type of meeting table join, just not sure where to start.

+2


source to share


2 answers


SELECT * FROM users 
LEFT JOIN Appointments ON Users.UserID=Appointments.UserID
WHERE Appointments.UserID is null

      



+7


source


Try the following:



SELECT * FROM users WHERE users.id NOT IN (SELECT user FROM appointments)

      

+5


source







All Articles