I am trying to find out the correct SQL query to carry out the following:
I have 2 tables and want to count total sum values of rows from one of them based on criteria selected from the other.
table1
| id | colour | item
| ------------------| ----------|
| 1 | blue | anorak
| 2 | blue | jeans
| 3 | green | t-shirt
| 4 | yellow | t-shirt
table2
| id | cost |
| ---------------|
| 1 | 58 |
| 2 | 22 |
| 3 | 36 |
| 4 | 19 |
So for example how do I find out total cost of all blue items? (Should amount to 80)
If it were all in one table I could do: SELECT SUM(cost) FROM table1 WHERE colour='blue';
How would I do this with the 2 tables?
thanks in advance