Reputation: 11663
id userid note created_date
1 100 x 2010-09-29 02:24:57
2 101 y some date
3 100 z some date
4 103 a "
5 100 b "
6 102 c "
I want to latest 2 result
of userid
100 and 102
. This is the situation to understand the problem. Actually I have a list of userid and I want the latest n result
of userid
which is in my list of userid
.
Upvotes: 0
Views: 48
Reputation: 2293
This was very difficult to understand but I'll give you three possible answers:
1) If you want the results by the highest user iD ("latest" could mean that), you should do
select * from table
order by userId desc
limit 0, 2
2) If you want them ordered by creation date (which "latest" could also mean), type
select * from table
order by created_date desc
limit 0, 2
3) if your "list of userid" is another table, you want to join it
select t.* from table t
inner join list_of_userid u
on u.userid = t.userid
order by created_date desc
limit 0, 2
If you actually want something else, you'll have to explain it :)
Upvotes: 1