Hi All
This should be easy enough for a pro sql guru.. Normally i could rise to the challenge but i seem to be stuck with this one.
I have Three tables which i've greatly simplified below:
Customers
CustID | CustName | Group |
1 | Mr Brown | G1 |
2 | Mr Black | G2 |
3 | Mr Pink | G2 |
4 | Mr Yellow| G3 |
Orders
CustID|OrderDate |OrderCode|OrderSeqNum|Description |
1 |10/02/2007|B21 |10 |mashed potato|
1 |15/03/2008|B44 |20 |another order|
2 |10/06/2006|A23 |10 |blah |
2 |02/08/2006|Q44 |20 |blah again |
3 |30/04/2006|ZZ1 |10 |cabbage |
3 |11/01/2008|NM3 |20 |dizzy kipper |
RequiredOrders
Group|OrderCode|
G1 |B21 |
G1 |NM3 |
G2 |B21 |
G2 |ZZ1 |
G3 |Q44 |
G3 |B21 |
G3 |B44 |
G3 |NM3 |
G3 |ZZ1 |
I need a list of Customers from the customers table as my outer query. Then i need details of the latest order but only where the order appears in the required orders list. Follow?
So based on the above my results would be the following:
1|Mr Brown|G1|10/02/2007|B21|10|mashed potato
3|Mr Pink |G2|30/04/2006|ZZ1|10|cabage
The only other thing to mention is that the "Orders" table is approaching 9 million records....
Thanks guys
sugarflux
This should be easy enough for a pro sql guru.. Normally i could rise to the challenge but i seem to be stuck with this one.
I have Three tables which i've greatly simplified below:
Customers
CustID | CustName | Group |
1 | Mr Brown | G1 |
2 | Mr Black | G2 |
3 | Mr Pink | G2 |
4 | Mr Yellow| G3 |
Orders
CustID|OrderDate |OrderCode|OrderSeqNum|Description |
1 |10/02/2007|B21 |10 |mashed potato|
1 |15/03/2008|B44 |20 |another order|
2 |10/06/2006|A23 |10 |blah |
2 |02/08/2006|Q44 |20 |blah again |
3 |30/04/2006|ZZ1 |10 |cabbage |
3 |11/01/2008|NM3 |20 |dizzy kipper |
RequiredOrders
Group|OrderCode|
G1 |B21 |
G1 |NM3 |
G2 |B21 |
G2 |ZZ1 |
G3 |Q44 |
G3 |B21 |
G3 |B44 |
G3 |NM3 |
G3 |ZZ1 |
I need a list of Customers from the customers table as my outer query. Then i need details of the latest order but only where the order appears in the required orders list. Follow?
So based on the above my results would be the following:
1|Mr Brown|G1|10/02/2007|B21|10|mashed potato
3|Mr Pink |G2|30/04/2006|ZZ1|10|cabage
The only other thing to mention is that the "Orders" table is approaching 9 million records....
Thanks guys
sugarflux