PHP查询还显示ID 75的结果

时间:2015-04-23 00:00:25

标签: php html mysql sql

我有以下查询。出于某种原因,它没有在id:75下显示用户的结果,这当然是我。

SELECT IF(friends.sender = 75, friends.recipient, friends.sender) AS id, users.firstname, users.lastname, feed.date, feed.time, feed.text, feed.userID, feed.ip
FROM friends
JOIN users
    ON (users.id = IF(friends.sender = 75, friends.recipient, friends.sender))
JOIN feed 
    ON (users.id = feed.userID)
WHERE friends.sender = 75
    OR friends.recipient = 75
 AND friends.status = 1
ORDER BY feed.date DESC, feed.time DESC

1 个答案:

答案 0 :(得分:0)

稍微猜测一下你试图完成的事情,但假设你想要返回用户及其朋友的列表,这样的事情应该有效:

SELECT DISTINCT users.id, users.firstname, users.lastname, 
    feed.date, feed.time, feed.text, feed.userID, feed.ip
FROM users 
JOIN friends
    ON users.id IN (friends.sender, friends.recipient)
JOIN feed 
    ON (users.id = feed.userID)
WHERE 75 IN (friends.sender,friends.recipient) 
    AND friends.status = 1
ORDER BY feed.date DESC, feed.time DESC