mysql - Duplicate result in join query -
here tables:
book (id ,title ,author ,isbn ,cost)
orders(orderid ,orderdate ,user(manytoone) ,orderitems(onetomany))
orderitem(id ,book(manytoone) ,quantity ,totalprice)
this query:
and here result:
but, result should had 2 rows
, contain orderid 1 , 2
not 4 rows.
you not joining on order correctly. looks doing cross join. see correct sql below.
select * orders o inner join orderitem oi on oi.orderid = o.orderid -- note additional join here inner join book b on b.id = oi.book_id
you can see on join have joined orders onto orderitem correctly. might need change id since not sure if should order_id, orderid or id. don't know schema.
Comments
Post a Comment