I have a table PICTURES
:
username varchar(50)
picture_id varchar(50)
datetime
...and I have a table FRIENDS
:
user_1 varchar(50)
user_2 varchar(50)
datetime
When you have friends on the website your username goes in user_1
, and your friend username's go in user_2
. For each new friend a new row...
I want to show the 5 last pictures of the friends of one user (user_1)
so I try
SELECT p.picture_id, p.datetime
FROM pictures AS p
WHERE p.username = (
SELECT f.user_2
FROM friends AS f
WHERE f.user_1 = '(ENTER USERNAME HERE)'
ORDER BY f.datetime DESC
LIMIT 5
)
ORDER BY p.datetime DESC;
And as you can see, the subquery return more than one row so... I need your help or suggestions to help me managing this solution!