Solved

Finding non-duplicate records

Posted on 2001-07-20
10
215 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
 
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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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 30

Accepted Solution

by:
hnasr earned 150 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 30

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

920 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

17 Experts available now in Live!

Get 1:1 Help Now