squale
September 15th, 2005, 08:06 PM
I have a simple table right now that has some rows listed like this:
Table Name = TicketStatus
TicketNumber TicketType Status Time
1 Normal In 09/15/2005 10:50:21
3 Normal In 09/11/2005 19:25:10
1 Normal Out 09/15/2005 11:45:10
3 Normal Out 09/11/2005 20:27:09
2 Normal In 09/14/2005 17:25:10
1 Normal Pay 09/15/2005 11:15:15
2 Normal Out 09/14/2005 21:45:30
What I want to do is select only 1 row per ticket number, and this row needs to be the row that has the LATEST time for that particular ticket number. Then I want to sort the results by ticket number decending. So for instance, the select I am looking for would bring me back ONLY the following rows in the following order:
TicketNumber TicketType Status Time
3 Normal Out 09/11/2005 20:27:09
2 Normal Out 09/14/2005 21:45:30
1 Normal Out 09/15/2005 11:45:10
My issue is I do not know how to go about selecting ONLY 1 row per ticket number, and the row I select has to be the row with the latest date for that particular ticket number.
Can any SQL gurus provide me with some code in order to do this? Thanks so much for the help guys!
Table Name = TicketStatus
TicketNumber TicketType Status Time
1 Normal In 09/15/2005 10:50:21
3 Normal In 09/11/2005 19:25:10
1 Normal Out 09/15/2005 11:45:10
3 Normal Out 09/11/2005 20:27:09
2 Normal In 09/14/2005 17:25:10
1 Normal Pay 09/15/2005 11:15:15
2 Normal Out 09/14/2005 21:45:30
What I want to do is select only 1 row per ticket number, and this row needs to be the row that has the LATEST time for that particular ticket number. Then I want to sort the results by ticket number decending. So for instance, the select I am looking for would bring me back ONLY the following rows in the following order:
TicketNumber TicketType Status Time
3 Normal Out 09/11/2005 20:27:09
2 Normal Out 09/14/2005 21:45:30
1 Normal Out 09/15/2005 11:45:10
My issue is I do not know how to go about selecting ONLY 1 row per ticket number, and the row I select has to be the row with the latest date for that particular ticket number.
Can any SQL gurus provide me with some code in order to do this? Thanks so much for the help guys!