kilrizzy
kilrizzy

Reputation: 2943

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.

Upvotes: 2

Views: 411

Answers (2)

JohnFx
JohnFx

Reputation: 34909

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

Upvotes: 7

Martin B
Martin B

Reputation: 24140

Try this:

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

Upvotes: 5

Related Questions