MySQL - Query All users WITHOUT an appointment
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 am assuming I would need some type of join with the appointments table, just not sure where to start.
SELECT * FROM users
LEFT JOIN Appointments ON Users.UserID=Appointments.UserID
WHERE Appointments.UserID is null
Try this:
SELECT * FROM users WHERE users.id NOT IN (SELECT user FROM appointments)
精彩评论