Solved

Finding non-duplicate records

Posted on 2001-07-20
10
203 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

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).

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

762 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