Reputation: 2943
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.
Upvotes: 2
Views: 411
Reputation: 34909
SELECT * FROM users
LEFT JOIN Appointments ON Users.UserID=Appointments.UserID
WHERE Appointments.UserID is null
Upvotes: 7
Reputation: 24140
Try this:
SELECT * FROM users WHERE users.id NOT IN (SELECT user FROM appointments)
Upvotes: 5