[英]How to get values from two table with subqueries?
I have two tables names are feed, and friendship.... 我有两个表,名字分别是feed和友谊。
friendship table has these fields..toid which the session user id, fromid which is the friend id, and status that may be 0 or 1, and the feed table contains id,post_user_id which is the feed poster id, and contents. 友谊表包含以下字段:.toid(会话用户ID),fromid(是朋友ID)以及状态(可能为0或1),并且供稿表包含id,post_user_id(即供稿发布者ID)和内容。 Now i want to get the feed from the feed table only from my friends i am able to get feeds from my friends but i can't get my own feed , when i put my own id in the condition the query is executed but the result empty.
现在我只想从我的朋友的提要表中获取提要,我可以从朋友的提要中获取提要,但是我无法获得自己的提要,当我将自己的ID置于条件中时,执行查询,但是结果空的。 i tried these
我尝试了这些
SELECT * FROM feed WHERE `post_user_id` IN (Select fromid from
gr_user_friendships where toid = 47) ORDER BY
post_date_time DESC
/****This query giving only the friends records not mine to get my records also i put my own id in the condition agains****/ / ****此查询仅提供朋友记录而不是我的记录以获取我的记录,我也将自己的ID放在条件中**** /
SELECT * FROM feed WHERE `post_user_id` IN (Select fromid from
gr_user_friendships where toid = 47) and `post_user_id` = 47 ORDER
BY post_date_time DESC
/*This time this results empty**/ / *这次结果为空** /
I also tried this with inner join no success at all 我也尝试了这种内连接完全没有成功
Shouldn`t it work with an OR instead of the AND? 它不应该使用OR而不是AND吗?
SELECT * FROM feed WHERE `post_user_id` IN (Select fromid from
gr_user_friendships where toid = 47) OR `post_user_id` = 47 ORDER
BY post_date_time DESC
In your second query: 在第二个查询中:
SELECT * FROM feed WHERE `post_user_id` IN (Select fromid from
gr_user_friendships where toid = 47) and `post_user_id` = 47 ORDER
BY post_date_time DESC
just replace and
with or
只需更换
and
用or
Try: 尝试:
SELECT * FROM feed WHERE post_user_id = 47 or 'post_user_id' IN
(Select fromid from gr_user_friendships where toid = 47) ORDER BY
post_date_time DESC
Try this.. 尝试这个..
SELECT * FROM feed INNER JOIN (Select fromid from
gr_user_friendships where toid = 47) WHERE 'toid' = 47 and `post_user_id` = 47 ORDER
BY post_date_time DESC
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.