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:

enter image description here

and here result:

enter image description here

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

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -