views:

94

answers:

2

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.

+5  A: 

Try this:

SELECT * FROM users WHERE users.id NOT IN (SELECT user FROM appointments)
Martin B
+7  A: 
SELECT * FROM users 
LEFT JOIN Appointments ON Users.UserID=Appointments.UserID
WHERE Appointments.UserID is null
JohnFx
Except of course, never use select * especially when you have a join.
HLGEM
Granted, only formed it that way because the OP didn't indicate which fields he needed in the query.
JohnFx