Hello, I have three tables and want to have a resultset where each unique AddressID is accompanied with lowest OrderID from table Sync_Orders. I've managed to create a GROUP BY AddressID and ORDER BY OrderID ASCbut the problem is that I have then (for example) 4 rows with the same AddressID and OrderID from low to high. If I want the unique/distinct AddressID, the OrderID is then random and cannot be trusted, MySQL does not support the LIMIT and GROUP BY I believe.
The only option, I guess, would be to work with subqueries. My knowledge of MySQL is limited and I cannot figure it out.
Below is a summary of the three tables. Multiple PhoneID's in the Sync_Orders table can be linked to one AddressID. I want to have unique AddressID with the lowest OrderID. I think the tables give a clear idea of what I want to achieve. Thanks for the help!
Table: Sync_Orders
OrderID | PhoneID |Orderdate
50 | 6 | 09/12/2010
49 | 5 | 08/12/2010
48 | 4 | 07/12/2010
47 | 3 | 06/12/2010
46 | 2 | 05/12/2010
45 | 1 | 04/12/2010
44 | 7 | 03/12/2010
43 | 9 | 02/12/2010
42 | 8 | 01/12/2010
41 | 7 | 30/11/2010
Table: Sync_Phone
PhoneID | AdresID
1 | 1
2 | 1
3 | 2
4 | 2
5 | 3
6 | 3
7 | 4
8 | 4
9 | 4
Table: Sync_Address
AddressID
1
2
3
4
Requested Result
Unique AddressID with lowest OrderID (== first Orderdate) from Sync_Orders
AddressID LowestOrderID Orderdate
1 | 45 | 04/12/2010
2 | 47 | 06/12/2010
3 | 49 | 08/12/2010
4 | 41 | 30/11/2010