如何选择多个子查询?

时间:2014-02-13 12:37:38

标签: sql

我不知道怎么称呼它。 我这张桌子就在这里:

phpMyAdmin screenshot

正如您可以看到Titon跟随SLH_444Knoedel_475。 现在,如何为Titon关注的用户选择所有行?

我希望usernameSLH_444Knoedel_475

的所有行的结果

http://sqlfiddle.com/#!2/4a986/1

这是我到目前为止所做的,但它是错误的,因为子查询返回的行数超过1行

SELECT * FROM ACTIVITIES 
WHERE targetname = 
(select targetname from ACTIVITIES 
where activity='followed' and username='Titon');

3 个答案:

答案 0 :(得分:2)

我想你想要:

SELECT * FROM ACTIVITIES 
WHERE username in 
(select targetname from ACTIVITIES 
where activity='followed' and username='Titon');

虽然Titon没有关注SLH_444,但他已关注SLB_444

答案 1 :(得分:1)

SELECT targetname FROM ACTIVITIES WHERE username = 'Titon' AND activity = 'followed';

答案 2 :(得分:0)

select * from tablename where activity='followed' and username='Titon'