I have two tables, one showing items users have bought from various stores, and the other which details who bought what.
Table A for products is:
prod_id
site_name
product
Table B for users is:
user_id
prod_id
I need to count the total number of products bought from a certain store. I can’t simply count from Table A as there may be the same products bought by several users but to keep the data tidy I store it as above.
Should I include the site_name in table B going forward as well to make it easier to simply count that, or can it be done in one query? I’d rather not bloat tables for the sake of a couple of queries as I think that would be bad database design but cannot work out how to do the count otherwise.
Is it possible?
You an use a join: