Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

Outer Join Failure in SQL Editor

Bobbins
8 - Asteroid

Good Morning,

In running this code, it is limiting me to the number of records found in Tbl_Warehouse despite there being plenty more records in Tbl_Delivery

Therefore, I believe i need an OUTER join. However, if i use the OUTER code, the SQL errors. What am i doing wrong?

 

Original code:

 

 

 

Select
Work_Tbl_Delivery.From_Warehouse_ID,
Work_Tbl_Delivery.PackageNumber,
Work_Tbl_Warehouse.Address,
Work_Tbl_Warehouse.ID

from Work_Tbl_Delivery

Join Work_Tbl_Warehouse

on Work_Tbl_Warehouse.ID = Work_Tbl_Delivery.From_Warehouse_ID

 

 

 

 

The below, despite using RIGHT still gives me the same number of records.

 

 

 

Select
Work_Tbl_Delivery.From_Warehouse_ID,
Work_Tbl_Delivery.PackageNumber,
Work_Tbl_Warehouse.Address,
Work_Tbl_Warehouse.ID

from Work_Tbl_Delivery

RIGHT Join Work_Tbl_Warehouse

on Work_Tbl_Warehouse.ID = Work_Tbl_Delivery.From_Warehouse_ID

 

 

 

I think i need to use OUTER RIGHT but it errors when i try to do so. The large amount of records i need is in Work_Tbl_Delivery

Thank you

1 REPLY 1
DataNath
17 - Castor

@Bobbins from the looks of your query:

 

RIGHT Join Work_Tbl_Warehouse

 

This means that Warehouse is your right-hand table and so if you're doing a right join, you'll get all of the records from Warehouse and those that match from Delivery, hence why you're seeing this result.

 

You can either switch the order of the query so that you initially pull fields from Warehouse and then right join on Delivery, or try doing LEFT JOIN instead as the table you want all values from is currently the left:

 

Select
Work_Tbl_Delivery.From_Warehouse_ID,
Work_Tbl_Delivery.PackageNumber,
Work_Tbl_Warehouse.Address,
Work_Tbl_Warehouse.ID

from Work_Tbl_Delivery

LEFT JOIN Work_Tbl_Warehouse

on Work_Tbl_Warehouse.ID = Work_Tbl_Delivery.From_Warehouse_ID
Labels