开发者

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜