2016-11-26 37 views

回答

1

簡單woulb是:

SELECT * from users a 
WHERE userid != :userid 
    AND not exists (select * from connections 
        where (userid = :userid and c_userid = a.userid) 
        or (userid = a.userid and c_userid = :userid)) 
+0

這個作品般的魅力 – Anand

0

下面將退回沒有在連接表中的所有用戶。

SELECT * FROM users AS u 
    WHERE (SELECT count(*) FROM connections AS c 
     WHERE c.userid=u.userid AND reqType != 0) = 0; 
0

下面的查詢獲取用戶不是與用戶ID相關聯= 1

select u.userid,u.name,u.email 
from connections 
left join users as u on connections.c_userid = u.userid 
where connections.userid =1 and connections.reqtype in (0,1) 
0

您嘗試此查詢

select *from users where userid not in (select c_userId from connenctions where where userid=1) and userid!=1