For example, I have a shop order database, and two tables in it - ORDERS and ORDERSTATUS.
Table : orders
--------------------------------------------
OrderID | OrderItems | AddedTimeStamp |
--------------------------------------------
1 | Apples | 2009-12-22 13:15:18 |
--------------------------------------------
2 | Bananas | 2009-12-22 14:15:24 |
--------------------------------------------
Table : orderstatus
--------------------------------------------------------------------
StatusID | OrderID | Status | AssignedUser | StatusTimestamp |
--------------------------------------------------------------------
1 | 1 | Received | JohnSmith | 2009-12-22 14:15:24 |
--------------------------------------------------------------------
2 | 2 | Received | MaryJane | 2009-12-22 14:15:24 |
--------------------------------------------------------------------
3 | 1 | Process | JohnSmith | 2009-12-22 14:15:24 |
--------------------------------------------------------------------
4 | 2 | Process | MaryJane | 2009-12-22 14:15:24 |
--------------------------------------------------------------------
5 | 2 | Deliver | MaryJane | 2009-12-22 14:15:24 |
--------------------------------------------------------------------
I am running this SQL query :
SELECT od.orderid, od.orderitems, os.status, os.assigneduser
FROM orders AS od INNER JOIN orderstatus AS os
ON od.orderid = os.orderid
GROUP BY os.orderid
ORDER BY os.orderid ASC
This returns me :
------------------------------------------------
OrderID | OrderItems | Status | AssignedUser |
------------------------------------------------
1 | Apples | Received | JohnSmith |
------------------------------------------------
2 | Bananas | Received | MaryJane |
------------------------------------------------
What I would like is :
------------------------------------------------
OrderID | OrderItems | Status | AssignedUser |
------------------------------------------------
1 | Apples | Process | JohnSmith |
------------------------------------------------
2 | Bananas | Deliver | MaryJane |
------------------------------------------------
I'm quite new to MySQL queries, but I've been banging my head for the past 4 hours - can someone help?? TIA.
EDIT : The basic objective is I want to show the latest status for the orders.