I have a table as follows:
Order_ID | Ship_num | Item_code | Qty_to_pick | Qty_picked | Pick_date |
---|---|---|---|---|---|
1111 | 1 | 1 | 3000 | 0 | Null |
1111 | 1 | 2 | 2995 | 1965 | 2021-05-12 |
1111 | 2 | 1 | 3000 | 3000 | 2021-06-24 |
1111 | 2 | 2 | 1030 | 0 | Null |
1111 | 3 | 2 | 1030 | 1030 | 2021-08-23 |
2222 | 1 | 3 | 270 | 62 | 2021-03-18 |
2222 | 1 | 4 | 432 | 0 | Null |
2222 | 2 | 3 | 208 | 0 | Null |
2222 | 2 | 4 | 432 | 200 | 2021-05-21 |
2222 | 3 | 3 | 208 | 208 | 2021-08-23 |
2222 | 3 | 4 | 232 | 200 | 2021-08-25 |
From this table, I only want to show the rows that has the latest ship_num information, not the latest pick_date information (I was directed to a question like this that needed to return the rows with the latest entry time, I am not looking for that) for an order i.e., I want it as follows
Order_ID | Ship_num | Item_code | Qty_to_pick | Qty_picked | Pick_date |
---|---|---|---|---|---|
1111 | 3 | 2 | 1030 | 1030 | 2021-08-23 |
2222 | 3 | 3 | 208 | 208 | 2021-08-23 |
2222 | 3 | 4 | 232 | 200 | 2021-08-25 |
I tried the following query,
select order_id, max(ship_num), item_code, qty_to_pick, qty_picked, pick_date
from table1
group by order_id, item_code, qty_to_pick, qty_picked, pick_date
Any help would be appreciated.
Thanks in advance.