I may need some hand holding here, my SQL knowledge is enough to get by but not amazing, I'll break it down simple as I can.
- I have two tables:
orders
andshippers
orders
has manyshippers
, related by theorderno
columnshippers
has amove_dt
column (date/time when the order is going to be shipped)
I want to sort orders
by the highest move_dt
in the shippers
table.
In other words: I want to list orders by the date/time they are shipping, and only show each order once.
This query gives me multiple instances of orders, one for each shipper it has:
select `orders`.*, `shippers`.`move_dt` from `orders`
join `shippers` on `shippers`.`orderno` = `orders`.`orderno`
order by `shippers`.`move_dt` desc
What do I need to do so each order shows only once? The query should return the same number of results as select * from orders
but be sorted by the highest move date in the shippers table.
I'm happy to post table structures and any other relevant info, and to have edits to my post that make it more clear.