SQL Join Diagram and Query

SQL Join Diagram and Query

SQL Join Diagram

SQL Join Diagram

Create TableA and TableB and Populate Data

LEFT JOIN : Select records from the first (left-most) table with matching right table records.

RIGHT JOIN : Select records from the second (right-most) table with matching left table records.

INNER JOIN : Select records that have matching values in both tables.

FULL OUTER JOIN : Selects all records that match either left or right table records.

Results from Above Queries in Order

Left Join Results – Select records from the first (left-most) table with matching right table records.

KeyValueKeyValue
AKAlaskaNULLNULL
ALAlabamaNULLNULL
AZArizonaNULLNULL
CACaliforniaNULLNULL
COColoradoCOColorado
WAWashingtonWAWashington

KeyValueKeyValue
COColoradoCOColorado
WAWashingtonWAWashington

Right Join Results – Select records from the second (right-most) table with matching left table records.

KeyValueKeyValue
NULLNULLARArkansas
COColoradoCOColorado
NULLNULLCTConnecticut
NULLNULLDEDelaware
NULLNULLFLFlorida
WAWashingtonWAWashington

Inner Join Results –¬†Select records that have matching values in both tables.

KeyValueKeyValue
COColoradoCOColorado
WAWashingtonWAWashington

Full Outer Join Results –¬†Selects all records that match either left or right table records.

KeyValueKeyValue
COColoradoCOColorado
WAWashingtonWAWashington
KeyValueKeyValue
AKAlaskaNULLNULL
ALAlabamaNULLNULL
AZArizonaNULLNULL
CACaliforniaNULLNULL
COColoradoCOColorado
WAWashingtonWAWashington
NULLNULLARArkansas
NULLNULLCTConnecticut
NULLNULLDEDelaware
NULLNULLFLFlorida

Leave a Reply

Your email address will not be published. Required fields are marked *

*