Results 1 to 10 of 10
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Query Join (2000)

    I have two tables that I am using in a query. How do I get all the records from both tables. I have an outer join on one table to get everything but I also want an outer join on the other table.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Query Join (2000)

    Jet SQL does not support two-sided outer joins. You will have to create two queries, one with a left join, the other with a right join. Then, create a union query to merge the results. The results of the two queries will overlap, but that doesn't matter, for the union query will weed out the duplicates by default.

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Query Join (2000)

    I created the two querys - one using an outer join for one table and then the other query using the outer join for the other table. I have never created a union query and I am not sure how to set it up. The following code was in Access help -
    Select [CompanyName], [City]
    From [suppliers]
    Union All Select [CompanyName], [City]
    From [Customers];

    Is this what you are talking about? If not could you tell me how to do this?

  4. #4
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Query Join (2000)

    That is what Hans was referring to, and your sample looks correct.
    Wendell

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Query Join (2000)

    You must write the SQL for a union query yourself. It goes like this:
    1. <LI>Note the names of the two queries you created.
      <LI>Start to create a new query in design view.
      <LI>Close the Show Table dialog without adding a table.
      <LI>Note that the view button on the left of the toolbar now says SQL. Click it (or select View | SQL)
      <LI>Change the SQL text from SELECT; to

      SELECT * FROM [Query1] UNION SELECT * FROM [Query2]

      where Query1 and Query2 are the names of your queries.
    You should be able to switch to datasheet view now. Not to design view, for union queries don't "fit" into the way design view works.

  6. #6
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Query Join (2000)

    Thank you so much - it worked perfectly.

  7. #7
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Query Join (2000)

    I"m back. How do I indicate unique values in that UNION query? I am getting duplicates.

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Query Join (2000)

    Do the individual queries return duplicates? If so, set their Unique Values property to Yes. As I wrote in a previous reply, UNION weeds out duplicates between the queries, but not those within the quueries.

    Another approach is to create yet a fourth query based on the union query, and set its Unique Values property to Yes.

  9. #9
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Query Join (2000)

    I brought the Union query into another query and indicated "unique values" but I am still getting duplicates. I want the record to be unique by just one field - the client number. The records that are duplicating, at least one field in the duplicate record is different.

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Query Join (2000)

    If at least one field is different, the records are not duplicates. If you don't want certain fields in the result, you must change the design of the queries with which you started. Only include the field(s) you need in the end result, omit the field(s) that cause the "duplicates".

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •