If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Select order

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-21-10, 11:22
betas betas is offline
Registered User
 
Join Date: Jan 2010
Posts: 9
Select order

Hello,

I'm using the following SELECT:

SELECT DISTINCT ticket.status, ticket.number, ticket.datum_status FROM ticket WHERE ticket.status IN(3,4) GROUP BY ticket.number ORDER BY ticket.datum_status DESC LIMIT 5;

I get the following result:

4, 'TRA-03-1050', '2010-01-17 13:21:57'
3, 'TRA19-1010', '2010-01-15 12:22:08'
3, 'TRA19-1000', '2010-01-15 12:16:24'

The row values are correct, except for the datum_status, which returns the oldest date, instead of the newest.

Any ideas on how to retrieve the newest?

Thanks!
Reply With Quote
  #2 (permalink)  
Old 01-21-10, 13:27
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
ORDER BY ticket.datum_status ASC
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 01-22-10, 03:32
betas betas is offline
Registered User
 
Join Date: Jan 2010
Posts: 9
Hello,

That will only order by result:

3, 'TRA19-1000', '2010-01-15 12:16:24'
3, 'TRA19-1010', '2010-01-15 12:22:08'
4, 'TRA-03-1050', '2010-01-17 13:21:57'

What I need is to retrieve the last modified value of these rows:

4, 'TRA-03-1050', '2010-01-17 13:21:57'
4, 'TRA-03-1050', '2010-01-17 13:24:08'
4, 'TRA-03-1050', '2010-01-17 13:24:15'
4, 'TRA-03-1050', '2010-01-17 13:25:04'
4, 'TRA-03-1050', '2010-01-17 13:25:20'
4, 'TRA-03-1050', '2010-01-17 13:43:39'

Any ideas?

Thanks
Reply With Quote
  #4 (permalink)  
Old 01-22-10, 03:44
aflorin27 aflorin27 is offline
Registered User
 
Join Date: Apr 2008
Location: Iasi, Romania
Posts: 317
SELECT ticket.number, MAX(ticket.datum_status)
FROM ticket
WHERE ticket.status IN(3,4)
GROUP BY ticket.number
ORDER BY ticket.datum_status DESC
LIMIT 5;
__________________
Florin Aparaschivei
Iasi, Romania
Reply With Quote
  #5 (permalink)  
Old 01-22-10, 04:29
betas betas is offline
Registered User
 
Join Date: Jan 2010
Posts: 9
Bingo!

Thanks!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On