我在mysql中有三个表..我正在使用mysqli
用户
- 用户标识
- 用户名
- 电子邮件Site_A的
- 用户标识
- 用户名
- 状态Site_B
- 用户标识
- 用户名
- 状态
现在,我希望用户表中的用户名不在 Site_A 或 Site_B ... 你能告诉我如何获得用户名吗?
我是mysql的新手。
答案 0 :(得分:2)
LEFT OUTER JOIN
可以帮助您:
SELECT u.username
FROM User u LEFT JOIN Site_A USING(username)
WHERE Site_A.username IS NULL
UNION
SELECT u.username
FROM User u LEFT JOIN Site_B USING(username)
LEFT JOIN Site_B USING(username)
WHERE Site_B.username IS NULL
SELECT u.username
FROM User LEFT JOIN Site_A USING(username)
LEFT JOIN Site_B USING(username)
WHERE Site_A.username IS NULL
AND Site_B.username IS NULL;
答案 1 :(得分:1)
您可以尝试此查询:
SELECT username
FROM User
WHERE username NOT IN (
SELECT username
FROM Site_A
UNION
SELECT username
FROM Site_B
)
这里是fiddle供您参考
答案 2 :(得分:0)
SELECT username
FROM User
WHERE username NOT IN (
SELECT username
FROM Site_A
UNION
SELECT username
FROM Site_B
)
答案 3 :(得分:0)
//tried and tested
SELECT username
FROM User
WHERE username NOT IN (
SELECT username
FROM Site_A
UNION
SELECT username
FROM Site_B
)