Photos: id, uid, 开发者_开发知识库date;
Friends: uid1, uid2, date, status;
I want show latest photos for friends of user. How do I do?
This will do it:
SELECT p.id
FROM Photos AS p, Friends AS f
WHERE p.uid = f.uid2 AND f.uid1 = ${userX.id}
ORDER BY p.date DESC
LIMIT 1;
SELECT id FROM photos WHERE uid IN (SELECT uid2 FROM friends WHERE uid1 = {$uid1} ORDER BY date DESC LIMIT 1);
I supposed that UID1 is the User and UID2 is the friend, this will retrieve all the IDs
精彩评论