user3117841
user3117841

Reputation:

How to fetch data Message wise?

I have table like this.

thread_id, message_id, tomsg, frommsg, msg, time, readstatus
1,1,[email protected],[email protected],Hi,"2013-12-04 18:06:58",0
2,1,[email protected],[email protected],Hello,"2013-12-06 11:11:11",0
3,1,[email protected],[email protected],"How R U ?","2013-12-18 11:55:15",0
4,2,[email protected],[email protected],sem1,"2013-12-04 18:06:58",1
5,2,[email protected],[email protected],sem2,"2013-12-06 11:11:11",0

Here , Comma Separates the column data. I don't have enough reputation so I can't Upload Image.

Now suppose I want dat that have only last thread of each message then what I ll have to do ? i.e. from message_id 1 last whole thread 3 row should be returned. any suggestion please ?

Upvotes: 3

Views: 49

Answers (1)

Saharsh Shah
Saharsh Shah

Reputation: 29051

Try this:

SELECT t.thread_id, t.message_id, t.tomsg, t.frommsg, t.msg, t.time, t.readstatus 
FROM (SELECT t.thread_id, t.message_id, t.tomsg, t.frommsg, t.msg, t.time, t.readstatus 
      FROM thread t ORDER BY t.message_id, t.thread_id DESC
     ) AS t
GROUP BY t.message_id

Upvotes: 3

Related Questions