Skip to content Skip to sidebar Skip to footer

Difficulty Understanding Logic Of Joines

I'll use the following query to illustrate my question: select a.shipperid, b.orderid, b.custid from shippers a inner join orders b on a.shipperid = b.shipperid Shi

Solution 1:

In your current query you are doing inner join which will give you output of only matching lines::

Joins

See in the image below for your better understanding.

So to answer your question, you need to do Left join in your case like::

select a.shipperid,
       b.orderid,
       b.custid
from shippers a 
left join orders b

on a.shipperid = b.shipperid

the result of this will be with null value of Orders if there is not any order on that shipping.

Solution 2:

your query only asks to get all the (shipper id, orderid, custid) tuples that could possibly be related to each other. In other words, for each tuple returned, then shipperid has at some point shipped orderid to custid. Now it is up to you if you want to to further constrain the query to narrow down to a subset of the results on other criteria.

Post a Comment for "Difficulty Understanding Logic Of Joines"