473,796 Members | 2,476 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Find duplicate records in multiple tables

I'm trying to find a way to search multiple tables for the same record.
Say I have 3 tables all with a name column, I need to search all 3
tables and find matching names. Is there an easy way to accomplish this?

Nov 13 '05 #1
1 10626
You can do this by stacking queries on top of each other.

1. Create a UNION query that keeps track of the table name and primary key
value for each record. This example shows how to do that with 2 tables, but
you can add more with another UNION. The SQL statement will look like this:
SELECT "Employee" AS TableName,
Employee.Employ eeID AS ID,
Employee.Surnam e AS FullName FROM Employee
UNION ALL SELECT "Client" AS TableName,
tClient.ClientN um,
tClient.Surname FROM tClient;
Save with the name "Query9".

2. Create another query that uses the first one as in input table. This one
returns only the names that are duplicated, and tells how many there are:
SELECT Query9.FullName ,
Count(Query9.ID ) AS CountOfID
FROM Query9
GROUP BY Query9.FullName
HAVING (((Count(Query9 .ID))>1));
Save with the name "Query10".

3. Create another query that shows you the duplicated records, including the
name of the table, the primary key value, and the duplicated name:
SELECT Query9.TableNam e,
Query9.ID,
Query9.FullName
FROM Query10 INNER JOIN Query9 ON Query10.FullNam e = Query9.FullName ;

If your situation is actually more complex, so that more than 1 field
defines the duplicate, you can included these other fields also in the
original UNION query and the GROUP BY of the middle query, and the JOIN of
the final query.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Brian" <br*******@char ter.net> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
I'm trying to find a way to search multiple tables for the same record.
Say I have 3 tables all with a name column, I need to search all 3
tables and find matching names. Is there an easy way to accomplish this?

Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5697
by: steevp | last post by:
Hi, Please excuse the newbie type question, but I am wracking my brains to solve what should be a simple query. I have three fields in a table F1, F2, F3. Any of the fields may contain duplicate data, but I am only interested in where only the first two fields match. I want to query and get only the records (all three fields) where there are duplicates in the first two fields, e.g.
1
1786
by: Jameel | last post by:
how do i find duplicate records in ASP.net/ADO.net , i know how to do it in classic asp, anything appreciated code,tutorial links etc.. (if rs.eof then add record else error message end if )
2
28909
by: Carroll | last post by:
I'm looking for a way in SQL to find duplicate records in a single table, that are the same based on 3 columns, regardless of what is in the other columns in the duplicate records. I would like to keep both records (or it could be more than 2 as well) where duplicate records are found. Also, I am interested in selecting all columns from the duplicate records. Thanks, Carroll Rinehart
3
3011
GrandMaster
by: GrandMaster | last post by:
Hi all I'm using MS Access 97 and in my current database (a flat single table database) I have a field for FirstName and one for FamilyName. I've been given two different lots of data to import but some have the same person repeated on both. The only difference is that there is another field that nominates which of the two batches of data that record is from. Therefore I need to make a find duplicate query which can find where both FirstName...
2
2074
by: nethravathy | last post by:
Hi, The following table namely elcbtripselect contains 5147 records.I want to know wether this table contains duplicate records or not. I tried with following query 1)SELECT elcbtripselect.ELCBTRIP_voltsMIN, elcbtripselect.ELCBTRIP_voltsMAX, elcbtripselect.ELCBTrip_is_partwinding, elcbtripselect.ELCBTrip_is_ydelta, elcbtripselect.ELCBTRIP_starter_size, elcbtripselect.ELCBTRIP_UnitFunction, elcbtripselect.ELCBTRIP_strcb_speedi_frame_ty,...
5
13911
by: Sheol | last post by:
Hello everyone! Can somebody please help me with this... I have a VB program that inputs Name and Address. I've made a database in MS Access using ADO Control: Table Name: Contacts Fields are: ID, CompanyName, CompanyAddress My only problem is that how can I find duplicate entries in the CompanyName field. I have an ADD command button when adding new Company Name from a textbox. What I would like to do is that before the program add the...
1
2917
by: colin-whitehead | last post by:
I have 2 tables tblReports primary key UPN, plus numeric fields Effort, Attain, etc tblComments numeric primary key ID & textfield Text In the Query I select each record from tblReports using UPN and for each of the numeric fields use DLookup to look up the Text in tblComments. the expression DLookUp("Text","tblComments","ID=" & tblReports!Effort)
4
4794
dlite922
by: dlite922 | last post by:
Short Version How do you find the difference between two database with the same structure but different data? with SQL (results will be ingested with PHP). Long Version Seems like a little daunting task for a SQL n00b like me, but I'm here to seek some guidance and clear my head from all the googling. I thought this would be common thing to do. I have two "database dumps" at different times, I want to know what data is different between...
1
3689
by: anantha raman | last post by:
Hai, I am a beginer in Developing ASP.NET webpage. I want to restrict duplicates while uploading the excel data and to inform the user that the perticular cell in excel contains duplicate value which is already exist in Sql Database.(Duplicates should be check in Excel (EMP_ID) against SQL (EMPLOYEE_ID) SQL DATABASE Table : Employees FiledName:EMPLOYEE_ID
0
9683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9529
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10457
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10176
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10013
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6792
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5443
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4119
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3733
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.