Solved

access query design not in join

Posted on 2014-11-05
9
223 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 50

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 50

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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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 50

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

691 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