如果我有两个表:用户和约会。我如何查询数据库以查找如下内容:
SELECT * FROM users WHERE (none of: appointments.user = user.id)
我假设我需要某种类型的约会与约会表,只是不知道从哪里开始。
答案 0 :(得分:7)
SELECT * FROM users
LEFT JOIN Appointments ON Users.UserID=Appointments.UserID
WHERE Appointments.UserID is null
答案 1 :(得分:5)
试试这个:
SELECT * FROM users WHERE users.id NOT IN (SELECT user FROM appointments)