Saphire
Saphire

Reputation: 1930

How to select with multiple subqueries?

I don't know how else to call this. I have this table right here:

phpMyAdmin screenshot

And as you can see Titon followed SLH_444 and Knoedel_475. Now, how can I select all rows for users whom Titon followed?

I expect a result of all rows where the username is either SLH_444 or Knoedel_475

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

This is what I have so far, but it errors because the subquery returns more than 1 row

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

Upvotes: 0

Views: 86

Answers (3)

Mike C
Mike C

Reputation: 3117

I think you want:

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

Although Titon has not followed SLH_444, he has followed SLB_444.

Upvotes: 2

Duikboot
Duikboot

Reputation: 1101

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

Upvotes: 1

Saddam Abu Ghaida
Saddam Abu Ghaida

Reputation: 6759

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

Upvotes: 0

Related Questions