要获得选定用户的待处理请求,我使用:
SELECT f1.asker_user_id AS friend_id
FROM friends AS f1
LEFT JOIN friends AS f2
ON f1.asked_user_id = f2.asker_user_id
AND f1.asker_user_id = f2.asked_user_id
WHERE f1.status = 1 AND f2.status IS NULL
AND f1.asked_user_id = 2
http://www.sqlfiddle.com/#!2/0f7a0d5/65它正确返回用户 3. VALUES (3,2,1)
但我想获得更多关于这个用户 3 的数据。
我需要name_surname
和avatar
从users
表。并且该用户的所有word_id
s 来自connections
table,作为回报,它将显示word
from words_en
based on word_id
。
感谢分配!
ps我试过这个:
SELECT a.name_surname,GROUP_CONCAT(Distinct w.word Order by w.word asc) AS words
FROM (
SELECT f1.asked_user_id AS friend_id,
f1.created,
u.name_surname,
u.avatar
FROM friends AS f1
LEFT JOIN friends AS f2 ON f1.asked_user_id = f2.asker_user_id
INNER JOIN users AS u ON f1.asked_user_id = u.id
AND f1.asker_user_id = f2.asked_user_id
WHERE f1.status = 1 AND f2.status IS NULL
AND f1.asker_user_id = 2
) a
LEFT JOIN connections c ON c.user_id = a.friend_id
LEFT JOIN words_en w ON c.word_id = w.id
GROUP BY 1;