Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 19-02-2009
Member
 
Join Date: May 2008
Posts: 69
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
Reply With Quote
  #2  
Old 19-02-2009
Member
 
Join Date: May 2008
Posts: 2,293
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'
Reply With Quote
  #3  
Old 19-02-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
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
Reply With Quote
  #4  
Old 19-02-2009
Member
 
Join Date: May 2008
Posts: 2,383
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
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #5  
Old 19-02-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
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))
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "SQL Query For Joining Three Tables"
Thread Thread Starter Forum Replies Last Post
Join two tables using SQL query vaib288932 Software Development 3 20-08-2010 12:01 PM
Joining avi.001 and avi.002 Roockie Windows Software 6 04-05-2010 11:12 AM
Want to make query dependent on another query. MACE Software Development 4 01-02-2010 05:22 PM
Turn on MySQL query cache to speed up query performance DMA2Superman Software Development 3 07-07-2009 10:26 AM
SQL query between 2 tables linked by many to many relationship Luis234 Software Development 2 09-05-2009 02:17 PM


All times are GMT +5.5. The time now is 01:32 PM.