SELECT M.post_id, M.uid_fk, M.message, M.image1,M.roles, M.created,U.uname, U.f_name, U.l_name
FROM posts M, person U
WHERE M.uid_fk=U.p_id
AND M.uid_fk in (
(select send_id from friend_request where p_id = '7' AND status=1)
or
(select p_id from friend_request where send_id = '7' AND status=1)
AND
(select send_id from follower_request where p_id = '7' AND status=1 AND M.uid_fk = '7')
AND
M.uid_fk = 7
)
order by M.post_id DESC
我无法获得当前数据。
如何获得这样的查询
SELECT M.post_id, M.uid_fk, M.message, M.image1,M.roles, M.created,U.uname, U.f_name, U.l_name
FROM posts M, person U
WHERE M.uid_fk=U.p_id
AND M.uid_fk in (1,2,3,4,7,8,9)
order by M.post_id DESC
答案 0 :(得分:0)
查看您的查询,我想您想获取在friend_request或follower_request表中具有条目的帖子数据。如果这就是您的意思,则可以对查询使用UNION:
SELECT M.post_id, M.uid_fk, M.message, M.image1,M.roles, M.created,U.uname, U.f_name,
U.l_name
FROM posts M, person U
WHERE
M.uid_fk = 7
AND M.uid_fk=U.p_id
AND M.uid_fk in (select send_id from friend_request where p_id = M.uid_fk AND
status=1)
UNION ALL
SELECT M.post_id, M.uid_fk, M.message, M.image1,M.roles, M.created,U.uname, U.f_name,
U.l_name
FROM posts M, person U
WHERE
M.uid_fk = 7
AND M.uid_fk=U.p_id
AND M.uid_fk in (select p_id from friend_request where send_id = M.uid_fk AND
status=1)
UNION ALL
SELECT M.post_id, M.uid_fk, M.message, M.image1,M.roles, M.created,U.uname, U.f_name,
U.l_name
FROM posts M, person U
WHERE
M.uid_fk = 7
AND M.uid_fk=U.p_id
AND M.uid_fk in (select send_id from follower_request where p_id = M.uid_fk AND
status=1)
ORDER BY post_id DESC
答案 1 :(得分:0)
很难知道您的实际意图,但这可能会有所帮助。
SELECT M.post_id, M.uid_fk, M.message, M.image1,M.roles, M.created,U.uname, U.f_name, U.l_name
FROM posts M
INNER JOIN person U ON M.uid_fk=U.p_id
WHERE M.uid_fk = 7
AND (
M.uid_fk in (select send_id from friend_request where p_id = '7' AND status=1)
OR M.uid_fk in (select p_id from friend_request where send_id = '7' AND status=1)
)
AND M.uid_fk in(select send_id from follower_request where p_id = '7' AND status=1)
ORDER BY M.post_id DESC
您不能在内部包含OR in()
,但可以通过OR将两个in()
连接起来