Solved

access query design not in join

Posted on 2014-11-05
9
215 Views
Last Modified: 2014-11-05
Can anyone provide a basic syntax, whereby you want to list all rows of data in one table that dont exist in another table. The tables are joined on a specific field. The query wizad has a few options but non that meet "not in" type queries. Any pointers?
0
Comment
Question by:pma111
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 49

Accepted Solution

by:
Vitor Montalvão earned 500 total points
ID: 40423573
For those kind of queries I like to use the NOT EXIST clause:
SELECT *
FROM Table1
WHERE NOT EXISTS (SELECT 1 
              FROM Table2
              WHERE Table2.ID = Table1.ID)

Open in new window

0
 
LVL 3

Author Comment

by:pma111
ID: 40423590
What does the "SELECT 1" do in this context?
0
 
LVL 49

Expert Comment

by:Vitor Montalvão
ID: 40423597
Since you don't want to return nothing you can use any constant value (1, 2,..., 'a', 'T', ...) or even NULL if you want. Doesn't matter what you put there will work. It's only because the SELECT needs to have a least a column name or a value.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:pma111
ID: 40423603
getting a syntax error for some reason in the

WHERE NOT EXISTS (SELECT 1
              FROM Table2
              WHERE Table2.ID = Table1.ID)

section. This is access 2010.
0
 
LVL 3

Author Comment

by:pma111
ID: 40423661
it was because the field had a - in it so required the [ ] 's
0
 
LVL 5

Expert Comment

by:ReneD100
ID: 40423681
Problem with the 'where not in' and 'where not exists' is that Access handles those very slowly I've noticed. What I normally do is link the tables through the key (in this case the 'ID') and then right click on the join in the designder, select 'show all records from table1', and put a 'IS NULL' on the ID from the 2nd table.
0
 
LVL 49

Expert Comment

by:Vitor Montalvão
ID: 40423689
Shouldn't be slow if the ID has index on it.
What you did in the designer is something like this with SQL syntax:
SELECT Table1.*
FROM Table1
LEFT OUTER JOIN Table2 ON Table2.ID = Table1.ID
WHERE Table2.ID IS NULL

Open in new window

0
 
LVL 5

Expert Comment

by:ReneD100
ID: 40423700
I know what I did ;) But since the question was about 'the query wizard' I am sure it's easier to explain how to use it in the designer rather than the SQL editor.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40423810
using the Query wizard, select Find Unmatched Query wizard
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question