Trying to get to grips with this query... and failing madly...
I am trying to get the total number of each product in a table, where the order number is taken from a different table.. like so..
Table 1
orderid | placed | paid
1 | no | no
2 | yes | yes
3 | yes | yes
Table 2
orderid | productnumber | quantity
1 | 2 | 2
2 | 2 | 4
2 | 3 | 1
3 | 3 | 2
3 | 1 | 9
From here we do this...
$query=mysql_query("SELECT orderid from table_1 where placed=yes and paid=yes");
//this would give us 2 & 3 as the orderid
Now I need to know, preferably in one statement, how to get the answer from table2 to give me
Product 1 - quantity 9
Product 2 - quantity 4
Product 3 - quantity 3
But I do not know where to start.... any ideas would be a treat..
Thanks,