468,514 Members | 1,664 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,514 developers. It's quick & easy.

select last update

333 100+
My query results has 3 rows but I only wanted to select the max date or the last update. How can i do this? I only wanted to pick the most current date which is the last record below:

1038651 2007-05-11 RMARTINEZ In-Service
1038651 2007-07-03 Equip Ret Pend Return Pending
1038651 2007-03-07 Import Returned

Expand|Select|Wrap|Line Numbers
  1.     SELECT ticket_number, MAX(ticket_status_history.addedDate) AS OrderDate, MAX(ticket_status_history.Tech_id) AS Tech_id,max(description)
  2.         FROM ticket_status_history WITH (NOLOCK)
  3.         INNER JOIN ticket_status ON ticket_status.id = ticket_status_history.current_status
  4.         WHERE 
  5.  ticket_number=1038651
  6.         GROUP BY ticket_number, description, ticket_number
May 12 '09 #1
2 2498
162 100+
try without GROUP BY and add ORDER BY 'ticket_status_history.addedDate` DESC LIMIT 1 that would take the last update from the top

Expand|Select|Wrap|Line Numbers
  1. SELECT ticket_number, MAX(ticket_status_history.addedDate) AS OrderDate, MAX(ticket_status_history.Tech_id) AS Tech_id,max(description) 
  2.         FROM ticket_status_history WITH (NOLOCK) 
  3.         INNER JOIN ticket_status ON ticket_status.id = ticket_status_history.current_status 
  4.         WHERE  
  5.  ticket_number=1038651 ORDER BY ticket_status_history.addedDate DESC LIMIT 1
May 12 '09 #2
i used this,worked for me

Expand|Select|Wrap|Line Numbers
  1. select max(timestamp),method,id from tables where 1 group by method,id order by timestamp desc 
May 4 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Marco | last post: by
17 posts views Thread by kalamos | last post: by
2 posts views Thread by Chris Plowman | last post: by
29 posts views Thread by pb648174 | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.