silversurfer19
Registered User.
- Local time
- Today, 19:54
- Joined
- Aug 20, 2008
- Messages
- 26
I have been using aggregation queries to seperate data into those where there is a count of more than one for that particular combination of premise name, address line 1 and postcode, and those where there is only one.
Here is the code for these queries:
and
From the results of these, I then have two more queries which reconstruct the original records, providing me with full details of records in two seperate lists, those with duplicate addresses, and those without.
Here are the queries for these:
I have used this process with a number of files without any problems. However I have tried it with another two files and both are dropping a fairly large number of records somewhere within the process, but I am unable to determine where or why.
Could anyone suggest to me why this might be and how I could fix the problem?
Many thanks
Here is the code for these queries:
Code:
SELECT [InputTable].[Premises Name (Full)], [InputTable].[Address 1], [InputTable].Postcode INTO [Duplicates Only]
FROM InputTable
GROUP BY [InputTable].[Premises Name (Full)], [InputTable].[Address 1], [InputTable].Postcode
HAVING (((Count(*))>1));
and
Code:
SELECT [InputTable].[Premises Name (Full)], [InputTable].[Address 1], [InputTable].Postcode INTO [Non Duplicates]
FROM InputTable
GROUP BY [InputTable].[Premises Name (Full)], [InputTable].[Address 1], [InputTable].Postcode
HAVING (((Count(*))=1));
From the results of these, I then have two more queries which reconstruct the original records, providing me with full details of records in two seperate lists, those with duplicate addresses, and those without.
Here are the queries for these:
Code:
SELECT InputTable.[Address Source], InputTable.[External Unique ID], InputTable.URN, InputTable.[Premises Name (Full)], InputTable.[Address 1], InputTable.[Address 2], InputTable.[Address 3], InputTable.City, InputTable.County, InputTable.Postcode, InputTable.Country, InputTable.[Telephone 1], InputTable.[TPS 1], InputTable.[Telephone 2], InputTable.[TPS 2], InputTable.SOHO, InputTable.[SIC Code], InputTable.[SIC Description], InputTable.[Major Category], InputTable.[Minor Category], InputTable.Ethnicity, InputTable.[Employee Number], InputTable.[Num Sites], InputTable.[SUV Contact ID], InputTable.[Contact Title], InputTable.[Contact First Name], InputTable.[Contact Last Name], InputTable.[Contact Job Title], InputTable.[Campaign Code], InputTable.Outcome, InputTable.[Date & Time], InputTable.[Inbound/Outbound], InputTable.[Gross Revenue], InputTable.[New Premises Name (Full)], InputTable.[New Address 1], InputTable.[New Address 2], InputTable.[New Address 3], InputTable.[New City], InputTable.[New County], InputTable.[New Postcode], InputTable.[New Country], InputTable.[New Telephone 1], InputTable.[New Contact Title], InputTable.[New Contact First Name], InputTable.[New Contact Last Name], InputTable.[New Contact Job Title]
FROM [Duplicates Only] INNER JOIN InputTable ON [Duplicates Only].Postcode = InputTable.Postcode
WHERE (([InputTable].[Premises Name (Full)] = [Duplicates Only].[Premises Name (Full)]) OR ([InputTable].[Premises Name (Full)] IS NULL AND [InputTable].[Premises Name (Full)] IS NULL)) AND (([InputTable].[Address 1] = [Duplicates Only].[Address 1]) OR ([InputTable].[Address 1] IS NULL AND [Duplicates Only].[Address 1] IS NULL))
UNION
SELECT InputTable.[Address Source], InputTable.[External Unique ID], InputTable.URN, InputTable.[Premises Name (Full)], InputTable.[Address 1], InputTable.[Address 2], InputTable.[Address 3], InputTable.City, InputTable.County, InputTable.Postcode, InputTable.Country, InputTable.[Telephone 1], InputTable.[TPS 1], InputTable.[Telephone 2], InputTable.[TPS 2], InputTable.SOHO, InputTable.[SIC Code], InputTable.[SIC Description], InputTable.[Major Category], InputTable.[Minor Category], InputTable.Ethnicity, InputTable.[Employee Number], InputTable.[Num Sites], InputTable.[SUV Contact ID], InputTable.[Contact Title], InputTable.[Contact First Name], InputTable.[Contact Last Name], InputTable.[Contact Job Title], InputTable.[Campaign Code], InputTable.Outcome, InputTable.[Date & Time], InputTable.[Inbound/Outbound], InputTable.[Gross Revenue], InputTable.[New Premises Name (Full)], InputTable.[New Address 1], InputTable.[New Address 2], InputTable.[New Address 3], InputTable.[New City], InputTable.[New County], InputTable.[New Postcode], InputTable.[New Country], InputTable.[New Telephone 1], InputTable.[New Contact Title], InputTable.[New Contact First Name], InputTable.[New Contact Last Name], InputTable.[New Contact Job Title]
FROM [Duplicates Only] INNER JOIN InputTable ON [Duplicates Only].[Premises Name (Full)] = InputTable.[Premises Name (Full)]
WHERE (([InputTable].[Postcode] = [Duplicates Only].[Postcode]) OR ([InputTable].[Postcode] IS NULL AND [InputTable].[Postcode] IS NULL)) AND (([InputTable].[Address 1] = [Duplicates Only].[Address 1]) OR ([InputTable].[Address 1] IS NULL AND [Duplicates Only].[Address 1] IS NULL))
UNION SELECT InputTable.[Address Source], InputTable.[External Unique ID], InputTable.URN, InputTable.[Premises Name (Full)], InputTable.[Address 1], InputTable.[Address 2], InputTable.[Address 3], InputTable.City, InputTable.County, InputTable.Postcode, InputTable.Country, InputTable.[Telephone 1], InputTable.[TPS 1], InputTable.[Telephone 2], InputTable.[TPS 2], InputTable.SOHO, InputTable.[SIC Code], InputTable.[SIC Description], InputTable.[Major Category], InputTable.[Minor Category], InputTable.Ethnicity, InputTable.[Employee Number], InputTable.[Num Sites], InputTable.[SUV Contact ID], InputTable.[Contact Title], InputTable.[Contact First Name], InputTable.[Contact Last Name], InputTable.[Contact Job Title], InputTable.[Campaign Code], InputTable.Outcome, InputTable.[Date & Time], InputTable.[Inbound/Outbound], InputTable.[Gross Revenue], InputTable.[New Premises Name (Full)], InputTable.[New Address 1], InputTable.[New Address 2], InputTable.[New Address 3], InputTable.[New City], InputTable.[New County], InputTable.[New Postcode], InputTable.[New Country], InputTable.[New Telephone 1], InputTable.[New Contact Title], InputTable.[New Contact First Name], InputTable.[New Contact Last Name], InputTable.[New Contact Job Title]
FROM [Duplicates Only] INNER JOIN InputTable ON [Duplicates Only].[Address 1] = InputTable.[Address 1]
WHERE (([InputTable].[Premises Name (Full)] = [Duplicates Only].[Premises Name (Full)]) OR ([InputTable].[Premises Name (Full)] IS NULL AND [InputTable].[Premises Name (Full)] IS NULL)) AND (([InputTable].[Postcode] = [Duplicates Only].[Postcode]) OR ([InputTable].[Postcode] IS NULL AND [Duplicates Only].[Postcode] IS NULL));
Code:
SELECT InputTable.[Address Source], InputTable.[External Unique ID], InputTable.URN, InputTable.[Premises Name (Full)], InputTable.[Address 1], InputTable.[Address 2], InputTable.[Address 3], InputTable.City, InputTable.County, InputTable.Postcode, InputTable.Country, InputTable.[Telephone 1], InputTable.[TPS 1], InputTable.[Telephone 2], InputTable.[TPS 2], InputTable.SOHO, InputTable.[SIC Code], InputTable.[SIC Description], InputTable.[Major Category], InputTable.[Minor Category], InputTable.Ethnicity, InputTable.[Employee Number], InputTable.[Num Sites], InputTable.[SUV Contact ID], InputTable.[Contact Title], InputTable.[Contact First Name], InputTable.[Contact Last Name], InputTable.[Contact Job Title], InputTable.[Campaign Code], InputTable.Outcome, InputTable.[Date & Time], InputTable.[Inbound/Outbound], InputTable.[Gross Revenue], InputTable.[New Premises Name (Full)], InputTable.[New Address 1], InputTable.[New Address 2], InputTable.[New Address 3], InputTable.[New City], InputTable.[New County], InputTable.[New Postcode], InputTable.[New Country], InputTable.[New Telephone 1], InputTable.[New Contact Title], InputTable.[New Contact First Name], InputTable.[New Contact Last Name], InputTable.[New Contact Job Title]
FROM [Non Duplicates] INNER JOIN InputTable ON [Non Duplicates].Postcode = InputTable.Postcode
WHERE ([InputTable].[Premises Name (Full)] = [Non Duplicates].[Premises Name (Full)] OR ([InputTable].[Premises Name (Full)] IS NULL AND [Non Duplicates].[Premises Name (Full)] IS NULL)) AND ([InputTable].[Address 1] = [Non Duplicates].[Address 1] OR ([InputTable].[Address 1] IS NULL AND [Non Duplicates].[Address 1] IS NULL))
UNION
SELECT InputTable.[Address Source], InputTable.[External Unique ID], InputTable.URN, InputTable.[Premises Name (Full)], InputTable.[Address 1], InputTable.[Address 2], InputTable.[Address 3], InputTable.City, InputTable.County, InputTable.Postcode, InputTable.Country, InputTable.[Telephone 1], InputTable.[TPS 1], InputTable.[Telephone 2], InputTable.[TPS 2], InputTable.SOHO, InputTable.[SIC Code], InputTable.[SIC Description], InputTable.[Major Category], InputTable.[Minor Category], InputTable.Ethnicity, InputTable.[Employee Number], InputTable.[Num Sites], InputTable.[SUV Contact ID], InputTable.[Contact Title], InputTable.[Contact First Name], InputTable.[Contact Last Name], InputTable.[Contact Job Title], InputTable.[Campaign Code], InputTable.Outcome, InputTable.[Date & Time], InputTable.[Inbound/Outbound], InputTable.[Gross Revenue], InputTable.[New Premises Name (Full)], InputTable.[New Address 1], InputTable.[New Address 2], InputTable.[New Address 3], InputTable.[New City], InputTable.[New County], InputTable.[New Postcode], InputTable.[New Country], InputTable.[New Telephone 1], InputTable.[New Contact Title], InputTable.[New Contact First Name], InputTable.[New Contact Last Name], InputTable.[New Contact Job Title]
FROM [Non Duplicates] INNER JOIN InputTable ON [Non Duplicates].[Address 1] = InputTable.[Address 1]
WHERE ([InputTable].[Premises Name (Full)] = [Non Duplicates].[Premises Name (Full)] OR ([InputTable].[Premises Name (Full)] IS NULL AND [Non Duplicates].[Premises Name (Full)] IS NULL)) AND ([InputTable].[Postcode] = [Non Duplicates].[Postcode] OR ([InputTable].[Postcode] IS NULL AND [Non Duplicates].[Postcode] IS NULL))
UNION SELECT InputTable.[Address Source], InputTable.[External Unique ID], InputTable.URN, InputTable.[Premises Name (Full)], InputTable.[Address 1], InputTable.[Address 2], InputTable.[Address 3], InputTable.City, InputTable.County, InputTable.Postcode, InputTable.Country, InputTable.[Telephone 1], InputTable.[TPS 1], InputTable.[Telephone 2], InputTable.[TPS 2], InputTable.SOHO, InputTable.[SIC Code], InputTable.[SIC Description], InputTable.[Major Category], InputTable.[Minor Category], InputTable.Ethnicity, InputTable.[Employee Number], InputTable.[Num Sites], InputTable.[SUV Contact ID], InputTable.[Contact Title], InputTable.[Contact First Name], InputTable.[Contact Last Name], InputTable.[Contact Job Title], InputTable.[Campaign Code], InputTable.Outcome, InputTable.[Date & Time], InputTable.[Inbound/Outbound], InputTable.[Gross Revenue], InputTable.[New Premises Name (Full)], InputTable.[New Address 1], InputTable.[New Address 2], InputTable.[New Address 3], InputTable.[New City], InputTable.[New County], InputTable.[New Postcode], InputTable.[New Country], InputTable.[New Telephone 1], InputTable.[New Contact Title], InputTable.[New Contact First Name], InputTable.[New Contact Last Name], InputTable.[New Contact Job Title]
FROM [Non Duplicates] INNER JOIN InputTable ON [Non Duplicates].[Premises Name (Full)] = InputTable.[Premises Name (Full)]
WHERE ([InputTable].[Postcode] = [Non Duplicates].[Postcode] OR ([InputTable].[Postcode] IS NULL AND [Non Duplicates].[Postcode] IS NULL)) AND ([InputTable].[Address 1] = [Non Duplicates].[Address 1] OR ([InputTable].[Address 1] IS NULL AND [Non Duplicates].[Address 1] IS NULL));
I have used this process with a number of files without any problems. However I have tried it with another two files and both are dropping a fairly large number of records somewhere within the process, but I am unable to determine where or why.
Could anyone suggest to me why this might be and how I could fix the problem?
Many thanks