SELECT u.* ,
(select CASE u.ID
WHEN u.ID in (select RequestedUserID from user_requestes where userID=3) THEN 0
ELSE 1
END) AS Accepted
FROM users u
WHERE u.ID <>3
and u.id not in (select friends.FriendID
from friends
where friends.UserID=3 or friends.FriendID=3)
order by u.Name asc
我試圖使用phpMyAdmin查詢不返回預期的結果
select RequestedUserID from user_requestes where userID=3
上面的查詢返回79
的結果來執行這個查詢
,如果我執行原來的查詢,我發現這個
接受s HOULD是0,而不是1
您從不限制原始查詢將「接受」值設置爲零,那麼您爲什麼要這樣做? –
你是什麼意思? – Sora
請參閱http://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-be-a-very-simple-sql-查詢 – Strawberry