如何获取用户列表?

时间:2013-11-22 05:05:29

标签: php mysql mysqli

我在mysql中有三个表..我正在使用mysqli

  

用户
    - 用户标识
    - 用户名
    - 电子邮件

     

Site_A的
    - 用户标识
    - 用户名
    - 状态

     

Site_B
    - 用户标识
    - 用户名
    - 状态

现在,我希望用户表中的用户名不在 Site_A Site_B ... 你能告诉我如何获得用户名吗?

我是mysql的新手。

4 个答案:

答案 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
)