Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Finding non-duplicate records

Posted on 2001-07-20
10
Medium Priority
?
268 Views
Last Modified: 2011-09-20
Hi

    I will seek anyone help. I will like to have a query or be able to filter out for me the non-duplicate records of two tables. EG

I have a table name Client1 no and another table called Client2.Inside have many records of part number.

Client1 table      client2 table
 ac-123             ftx-454
 23-tt              23-tt
 tg-t               tg-t
 er-45              hg-33
.......
and many others. So how can i able to run any query or whatever and abel; to filter out only those which are not common and which table it came from. pls enlighten me

Thnaks
roger1
     
0
Comment
Question by:roger1102598
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 2

Expert Comment

by:hotbudare
ID: 6304186
Use:
======================================================
SELECT Query1.Client, Query1.Source
FROM Query1 LEFT JOIN Query2 ON Query1.Client = Query2.Client
WHERE (((Query2.Client) Is Null));
======================================================

WHERE Query1:
======================================================
SELECT Table1.Client, "Table1" AS Source
FROM Table1;
======================================================

AND Query2:
======================================================
SELECT Table2.Client, "Table2" AS Source
FROM Table2;
======================================================


HTH/EQTA
T.S.U. Mario Osorio
Punto Fijo, Falcon, Venezuela

0
 
LVL 54

Expert Comment

by:nico5038
ID: 6304424
roger1,

You use for this the "outer join".
Access has for this the LEFT and RIGHT join. When you use the graphical query editor you can set the direction of a link between tables (just drag and drop the field needed to get a link). Just double-click the line and select option 2 or 3 from the properties window.

This type of relation forces all recordsfrom one table to appear. When you set a "Is Null" in the table the relation is pointing to, then you get only non matching records from the "master table". However, this also needs to be done in the other direction.
Just create a second link pointing the other direction and having the "Is Null" on the field of the other table.
Now to get all non matching in one query you create finally one that combines both like:

select * from qryLeft
union
select * from qryRight;

This has to be typed in the SQL mode, as access doesn't support "graphical unions".

Clear ?

Nic;o)
0
 

Expert Comment

by:senan072100
ID: 6304674
dear roger

ill make ur life easer
1-u open the database windows
2-select new query(wizard)
3-select "find unmatched query wizard"
4-follow it up
5- ur query is ready

may u have any question please let me know
Senan


0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 54

Expert Comment

by:nico5038
ID: 6304774
Senan,

Unmatch can go into two directions:
1) In table1 and NOT in table2
2) In table2 and NOT in table1
This makes it clear why I propose a UNION.

The "easy" wizard will only supply you with ONE.

As roger1 also wants to know from what table the unmatch originates, indicates he wants BOTH.
When you add in "my" qryLeft a cell with "TableFrom:'Table1'"
and in the other a referene to Table2, the UNION will provide all wanted information.

Nic;o)
0
 

Expert Comment

by:senan072100
ID: 6305258
ops sorrey, i got the point
I'll check and let u know
senan
0
 
LVL 6

Expert Comment

by:bknouse
ID: 6306054
Select "Table1", [Part_Num]
From Table1 A
Where Not Exists (Select 1
From Table2 B
Where A.Part_Num = B.Part_Num)

Union

Select "Table2", [Part_Num]
From Table2 C
Where Not Exists (Select 1
From Table1 D
Where C.Part_Num = D.Part_Num)

Brent

0
 
LVL 54

Expert Comment

by:nico5038
ID: 6306068
Hi Brent,

Effectively your proposal will work too, however:
1) Typing this in the QBE editor is not that "easy"
2) Access performs upto 4 times faster on queries as on the subqueries you propose...

Nic;o)
0
 
LVL 31

Accepted Solution

by:
hnasr earned 450 total points
ID: 6306814
'This is a try
'Table1 with field partno
'Table2 with field partno
'your sample data entered
'Client1 table      client2 table
'ac-123             ftx-454
'23-tt              23-tt
'tg-t               tg-t
'er-45              hg-33

SELECT Client1.partno, "Client1" AS [Table]
FROM Client1
WHERE (((Client1.partno) Not In (select partno from client2)));
Union
SELECT Client2.partno, "Client2" AS [Table]
FROM Client2
WHERE (((Client2.partno) Not In (select partno from client1)));

'result
'partno       Table
'ac-123      Client1
'er-45       Client1
'ftx-454     Client2
'hg-33       Client2

'Good luck
0
 
LVL 54

Expert Comment

by:nico5038
ID: 6309172
Why such a cripple subquery solution ?
0
 
LVL 31

Expert Comment

by:hnasr
ID: 6309667
Thanks roger1 that u found my contribution useful.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

927 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