Solved

access query design not in join

Posted on 2014-11-05
9
203 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
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 45

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 45

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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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 45

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 119

Expert Comment

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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now