Grouping and retrieving most recent entry in a table for each group

Posted by Lisa on Stack Overflow See other posts from Stack Overflow or by Lisa
Published on 2010-05-24T19:13:14Z Indexed on 2010/05/24 19:21 UTC
Read the original article Hit count: 177

Filed under:

First off, please bear with me if I don't state the SQL question correctly.

I have a table that has multiple columns of data. The selection criteria for my table groups based on column 1(order #). There could be multiple items on each order, but the item #'s are not grouped together.

Example:

Order   Customer    Order Date  Order Time  Item    Quantity  
123456  45  01/02/2010  08:00   140 4  
123456  45  01/02/2010  08:30   270 29  
123456  45  03/03/2010  09:00   140 6  
123456  45  04/02/2010  09:30   140 10  
123456  45  04/02/2010  10:00   270 35  

What I need is a result like:

Order   Customer    Order Date  Order Time  Item    Quantity  
123456  45  04/02/2010  09:30   140 10  
123456  45  04/02/2010  10:00   270 35  

This result shows that after all the changes the final order includes 10 of Item 140 and 35 of Item 270.

Is this possible.

python

© Stack Overflow or respective owner

Related posts about sql