Hi guys~! What I am trying to do is take two tables group them, count them then subtract the results. I think I may need a table join but I am not sure? :p Here is what my data looks like.
Table 1:
id | user_id | item_id | item_name
1 | 2 | 1 | apple
2 | 2 | 1 | apple
3 | 2 | 2 | orange
4 | 2 | 3 | banana
5 | 2 | 3 | banana
When grouped and counted is:
apple 2
orange 1
banana 2
Table 2: (needs to be subtracted from table 1)
id | user_id | item_id | item_name
1 | 2 | 1 | apple
3 | 2 | 2 | orange
4 | 2 | 3 | banana
When grouped and counted is:
apple 1
orange 1
banana 1
The information I am trying to get should be:
item_name | amount
apple | 1
orange | 0
banana | 1
Here is my current function that will count and group one table:
function doReadItem($id) {
$sql = sprintf("SELECT *, count(item_name) as amount
FROM user_items
WHERE user_id = $id
GROUP BY item_name");
$result = mysql_query($sql);
return $result;
}
A push in the right direction would be soooo nice~ :quiet: