Have two tables which display owner information for their registered dogs; one for 2018 and another for 2019. Each table has the same columns, names, etc.
I need to only list the one full record by the license number. For example, the dog may not have been registered in 2019, but was registered in 2018. So I need to list the 2018 record if it's not contained in the 2019 table. If there are two records (one for 2018 and another for 2019), I only want to the 2019 record listed.
Union doesn't work namely because the "RegNumber" or dog tag numbers changes from year to year; not to mention possible address changes, etc. I've tried a combination of union, intersect and except and nothing seems to work properly. Any ideas?
SELECT [License Number] AS [LicenseNumber], [Last Name] AS [LastName], [First Name] AS [Firstname], [Street Name] AS [StreetName], [Address2], [City], [State], [Zip], [Phone], '' AS [Email], [Reg Number] AS [RegNumber], [Dog Name] AS [DogName], [Dog Breed] AS [Breed], [Purchased] AS [Year], [Sex], [Altered], [Color], [Vet] AS [Veterinarian], [RabieTag] AS [RabiesTagNumber], [RabiesTag_Exp] AS [RabiesTagExpiration], [Dog Number] AS [OwnerID], [Reg Number] AS [TagNumber]
FROM [dbo].[Dog_Info_2019]
WHERE Flag is not null
UNION
SELECT [License Number] AS [LicenseNumber], [Last Name] AS [LastName], [First Name] AS [Firstname], [Street Name] AS [StreetName], [Address2], [City], [State], [Zip], [Phone], '' AS [Email], [Reg Number] AS [RegNumber], [Dog Name] AS [DogName], [Dog Breed] AS [Breed], [Purchased] AS [Year], [Sex], [Altered], [Color], [Vet] AS [Veterinarian], [RabieTag] AS [RabiesTagNumber], [RabiesTag_Exp] AS [RabiesTagExpiration], [Dog Number] AS [OwnerID], [Reg Number] AS [TagNumber]
FROM [dbo].[Dog_Info_2018]
WHERE Flag is not null
ORDER BY [LicenseNumber]
When I execute the above query, both 2018 and 2019 records are shown for a total of 22569 records; 11176 rows are in the 2018 table and 11176 rows are in the 2019 table.
I've even tried NOT IN, but this only lists the records which aren't in one table or the other.
Thanks..