Results 1 to 5 of 5

Thread: SQL Query For Joining Three Tables

  1. #1
    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

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    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'

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    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

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    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

  5. #5
    Join Date
    Feb 2008
    Posts
    1,852

    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))

Similar Threads

  1. Join two tables using SQL query
    By vaib288932 in forum Software Development
    Replies: 3
    Last Post: 20-08-2010, 12:01 PM
  2. Joining avi.001 and avi.002
    By Roockie in forum Windows Software
    Replies: 6
    Last Post: 04-05-2010, 11:12 AM
  3. Want to make query dependent on another query.
    By MACE in forum Software Development
    Replies: 4
    Last Post: 01-02-2010, 05:22 PM
  4. Turn on MySQL query cache to speed up query performance
    By DMA2Superman in forum Software Development
    Replies: 3
    Last Post: 07-07-2009, 10:26 AM
  5. SQL query between 2 tables linked by many to many relationship
    By Luis234 in forum Software Development
    Replies: 2
    Last Post: 09-05-2009, 02:17 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,994,506.62460 seconds with 17 queries