I'm having trouble getting some data extracted from a db in the manner I'm looking for. The db looks like this:
tbl.product
- prod_id
- dist_id
- name
- date
tbl.sales1
- prod_id
- cat_id
- sold
tbl.sales2
- prod_id
- cat_id
- sold
tbl.category
- cat_id
- cat_name
I want to extract the data so that it is the format:
prod_id, name, date, sold(sales1), sold(sales2), cat_name
The same prod_id can be in both sales tables, or not.
So far I've got:
select p.prod_id, p.name, p.date,
(select sold from sales1 where sales1.prod_id = p.prod_id) as sales1_volsold,
(select sold from sales2 where sales2.prod_id = p.prod_id) as sales2_volsold
from product as p
where p.dist_id=111
This gets me the sales fine, but I'm not sure how to include the cat_name for each product with the sales.
Any help is appreciated.