All pastes #164808 Raw Edit

Someone

public text v1 · immutable
·published 2006-09-09 00:46 UTC
rendered paste body
friends
-------------
fid  |  userid1  |  userid2
----------------------------
 1   |    2      |    3
 2   |    2      |    7
 3   |    5      |    2
 

members
------
id    | name
---------------------------
2     |  mike
3     |  sara
5     |  joe
7     |  tom


entries
--------------
entryID  |  title  | userLink  | timestamp
--------------------------------------------
1        | bla     |   3       |   10
2        | heh     |   5       |   10
3        | test    |   5       |   20
4        | test2   |   7       |   10
5        | test5   |   7       |   20
6        | lalal   |   7       |   30


what I need is a query to get all the friends of members.id=2 to get the latest entry based on the highest value of the timestamp.. so i want to see something like

entryID  | timestamp | members.id
-------------------------------------------
1        |   10      |  3
3        |   20      |  5
6        |   30      |  7


Here is a query i have.. the column names are a bit different,, i need some pointers and help if i can do this in one query

SELECT members.id,picture,photos,title FROM members INNER JOIN entries ON members.id=userid WHERE members.id IN (SELECT members.id FROM friends, members WHERE ((members.id = friends.userid1 AND friends.userid2 = 2) OR (members.id = friends.userid2 AND friends.userid1 = 2)) AND status = 1) 

that should get 44.. but it gets around 600ish.. it gets ALL users entries