SQL Query For Joining Three Tables
hi
I am having problem regarding sql query.
My query consists of three tables in MS Access that I want to join the together.
My query is:
SELECT * from (Customer_Details
left join EMAS on Customer_Details.street_name = EMAS.street_name )
left join work_orders on Customer_Details.ID = work_orders.customer_ID
where Proceed_Retrofit = 'yes'
Now this query gives me various identical records which actually does not exist.
I want to view the three relevent records (where Proceed_Retrofit = 'yes') from Customer_details and the associated data from the other tables.
please help me regarding his sql query.
your views will be appreciated
Re: SQL Query For Joining Three Tables
I guess this query should work as a solution for you:
SELECT Distinct *
from Customer_Details
Left Outer join EMAS
on Customer_Details.street_name = EMAS.street_name
Left Outer join work_orders
on Customer_Details.ID = work_orders.customer_ID
where Proceed_Retrofit = 'yes'
Re: SQL Query For Joining Three Tables
i gues this is where the "duplicates" arise...
do you have a proper key to this table..?
if you have the error is solved.
try using a proper key for your query
Re: SQL Query For Joining Three Tables
this will definitely work for you
SELECT p.Name, v.Name
FROM Production.Product p
JOIN Purchasing.ProductVendor pv
ON p.ProductID = pv.ProductID
JOIN Purchasing.Vendor v
ON pv.VendorID = v.VendorID
WHERE ProductSubcategoryID = 15
ORDER BY v.Name
and the result is:
LL Mountain Seat/Saddle Chicago City Saddles
ML Mountain Seat/Saddle Chicago City Saddles
HL Mountain Seat/Saddle Chicago City Saddles
LL Road Seat/Saddle Chicago City Saddles
ML Road Seat/Saddle Chicago City Saddles
HL Road Seat/Saddle Chicago City Saddles
LL Touring Seat/Saddle Chicago City Saddles
Re: SQL Query For Joining Three Tables
try this one:
SELECT Abbrevdesc FROM T_abbrevs
WHERE Abbrevcode IN
(Select Abbrevcode FROM T_Companies_Abbrevs
WHERE CompanyID IN
(SELECT CompanyID FROM T_Corp_Companies))