SELECT l.log
FROM
(
SELECT f.friendid id
FROM tb_friend f
WHERE f.userid = tmpuserid/*tmpuserid是你要为其查找朋友及关注人的userid*/
UNION
SELECT a.touserid id
FROM tb_attention a
WHERE a.userid = tmpuserid/*tmpuserid是你要为其查找朋友及关注人的userid*/
)tb_id,
tb_log l
WHERE tb_id.id = l.userid
[Quote=引用 6 楼 studentaccp 的回复:]
引用 2 楼 vber1010 的回复:
select log from tb_log where userId in (select friendid from tb_friend where userid=&id union all select touserid from tb_attention where userid=&id)
[Quote=引用 2 楼 vber1010 的回复:]
select log from tb_log where userId in (select friendid from tb_friend where userid=&id union all select touserid from tb_attention where userid=&id)
[/Quote]
这个不错 啊,把in改成exists就更好了,再给列都起别名以减少解析时间。
select log from tb_log where userId in (select friendid from tb_friend where userid=&id union all select touserid from tb_attention where userid=&id)
[/Quote]