我试图从表A中获取表B中不存在的具有特定MeetingID的所有用户名 就像iam试图获得Meetingid:2,表A应该返回用户测试并将其余部分保留。 MeetingID 6返回Test。 这可以用一个查询吗?
表A: ID,用户名1测试2测试3 Testood
表B: Meetingid,用户名2测试2 Testood 6测试6 Testood
这是我一直努力工作的代码:
SELECT members.username FROM members RIGHT JOIN attendmeeting ON
attendmeeting.username=members.username WHERE attendmeeting.username
NOT LIKE members.username ORDER BY username DESC
表A是成员,表B是出席会议。我不知道如何基于会议ID来过滤掉它。
=============================================== =====
编辑: 感谢Harsh Gupta,第一部分现在正在运作。 最后一件事是仅使用与这些成员的特定会议ID来过滤掉NOT LIKE。
当前代码:
SELECT members.username
FROM members
LEFT JOIN attendmeeting
ON attendmeeting.username = members.username
WHERE attendmeeting.username IS NULL
ORDER BY members.username DESC
答案 0 :(得分:1)
我不确定你的tableA和tableB是哪个:
SELECT members.username
FROM members
LEFT JOIN attendmeeting
ON attendmeeting.username = members.username
WHERE attendmeeting.username IS NULL
ORDER BY members.username DESC
编辑:
SELECT members.username
FROM members
LEFT JOIN attendmeeting
ON attendmeeting.username = members.username
WHERE attendmeeting.username IS NULL
AND attendmeeting.username = 2
ORDER BY members.username DESC
HTH
答案 1 :(得分:0)
SELECT username FROM members WHERE username NOT IN(SELECT username FROM attendmeeting WHERE meetingid=?) ORDER BY username ASC
我正在寻找的查询。