I have five tables and when I try to list all items of a buy, if the item has size it should show the code of size of the product, i.e:
# tb_product
product_id
product_name
product_cod
# tb_size
size_id
size_name
# tb_product_size
product_id
size_id
product_size_cod
# tb_buy
buy_id
~
# tb_buy_item
product_id
size_id
buy_id
Here is the query:
select b.product_name,b.product_cod,c.size_name from tb_buy_item a
inner join tb_product b using(product_id)
left join tb_size c using(size_id)
where buy_id=x
The problem is when the item has size and how to show the code of this size.
I tried to do something like:
select b.product_name,b.product_cod,c.size_name from tb_buy_item a
inner join tb_product b using(product_id)
left join(tb_size c inner join tb_product_size d on c.size_id=d.size_id and d.product_id=b.product_id) a.size_id=c.size_id
where buy_id=x
but that shows this error:
unknown column 'b.product_id'