Hello!
I am trying to query a MySQL table and retrieve either the earliest or the
latest message in each thread. The messages are in a table with MsgID being
the primary key and fThreadID identifying to which thread the message
belongs.
Examples below.
Any ideas on the SQL I need to use here?
Thank you!
Ben :-)
Ben Gribaudo - Baltimore, MD - www.bengribaudo.com
"For God so loved the world, that he gave his only begotten Son, that
whosoever believeth in him should not perish, but have everlasting life."
John 3:16
Example Table
=============
MsgID (primary key) fThreadID ReceivedTimesta mp (DateTime)
1 99 2004-01-02 11:10:15
2 99 2004-02-01 01:11:59
3 99 2004-05-17 18:15:01
4 102 2004-07-01 11:11:29
4 103 2004-07-01 11:11:11
Example Desired Result Set #1
(earliest msg from each thread)
=============== =============== =
MsgID, fThreadID, ReceivedTimesta mp
1 99 2004-01-02 11:10:15
4 103 2004-07-01 11:11:11
Example Desired Result Set #2
(most recent msg from each thread)
=============== =============== ====
MsgID fThreadID ReceivedTimesta mp
3 99 2004-05-17 18:15:01
4 102 2004-07-01 11:11:29
I am trying to query a MySQL table and retrieve either the earliest or the
latest message in each thread. The messages are in a table with MsgID being
the primary key and fThreadID identifying to which thread the message
belongs.
Examples below.
Any ideas on the SQL I need to use here?
Thank you!
Ben :-)
Ben Gribaudo - Baltimore, MD - www.bengribaudo.com
"For God so loved the world, that he gave his only begotten Son, that
whosoever believeth in him should not perish, but have everlasting life."
John 3:16
Example Table
=============
MsgID (primary key) fThreadID ReceivedTimesta mp (DateTime)
1 99 2004-01-02 11:10:15
2 99 2004-02-01 01:11:59
3 99 2004-05-17 18:15:01
4 102 2004-07-01 11:11:29
4 103 2004-07-01 11:11:11
Example Desired Result Set #1
(earliest msg from each thread)
=============== =============== =
MsgID, fThreadID, ReceivedTimesta mp
1 99 2004-01-02 11:10:15
4 103 2004-07-01 11:11:11
Example Desired Result Set #2
(most recent msg from each thread)
=============== =============== ====
MsgID fThreadID ReceivedTimesta mp
3 99 2004-05-17 18:15:01
4 102 2004-07-01 11:11:29
Comment