?
Solved

access query design not in join

Posted on 2014-11-05
9
Medium Priority
?
226 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 51

Accepted Solution

by:
Vitor Montalvão earned 2000 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 51

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
Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

 
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 51

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
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.
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

764 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