I have three (3) tables in my query. The first table (Table 1) has customer data such as name but does not have the account id. Please note that the customer name in Table 1 does not match our customer database so some records require manual lookup. The second table (Table 2) has name and account id from our database. Third table (Table 3) is the list of any previous manual lookups of the account name.
What I'm hoping to do is create a query that states, if you can not find the account name that is in Table 1 when joined to Table 2, then return the value from Table 3.
I'm doing a left join from Table 1 to Table 2 on company Name and another Left Join from Table 1 to Table 3 on Company name. The issue when I do this is that I end up creating duplicates. I
Below is my SQL. I must be doing something wrong, but not sure what exactly. Any and all help is much appreciated.
SELECT DISTINCT Registrations.[User ID] AS RegID, Registrations.[Registration Date], Registrations.[First Name], Registrations.[Last Name], Registrations.Email, Registrations.[Company Website], Registrations.[Company Name], Registrations.[Job Title], Registrations.[REG: Job Title Category], Registrations.[REG: Primary Role2], Registrations.[REG: Market1], Registrations.City, Registrations.State, Registrations.Zip, Registrations.Country, Registrations.Phone, Registrations.[Alternate Phone], Registrations.[User ID], Registrations.[REG: Registration Type], Accounts.[Account ID], Accounts.[Account ID 18], Accounts.[PS Company Id], IIf(IsNull([Accounts].[Account Name]),1,0) AS Not_Found, IIf([Not_Found]=1,[Manual Account Lookup].[Account Name],[Accounts].[Account Name]) AS FoundAccountName, Registrations.[Current Packages (comma delimited)]
FROM (Registrations LEFT JOIN [Manual Account Lookup] ON Registrations.[Company Name] = [Manual Account Lookup].Company) LEFT JOIN Accounts ON Registrations.[Company Name] = Accounts.[Account Name];
What I'm hoping to do is create a query that states, if you can not find the account name that is in Table 1 when joined to Table 2, then return the value from Table 3.
I'm doing a left join from Table 1 to Table 2 on company Name and another Left Join from Table 1 to Table 3 on Company name. The issue when I do this is that I end up creating duplicates. I
Below is my SQL. I must be doing something wrong, but not sure what exactly. Any and all help is much appreciated.
SELECT DISTINCT Registrations.[User ID] AS RegID, Registrations.[Registration Date], Registrations.[First Name], Registrations.[Last Name], Registrations.Email, Registrations.[Company Website], Registrations.[Company Name], Registrations.[Job Title], Registrations.[REG: Job Title Category], Registrations.[REG: Primary Role2], Registrations.[REG: Market1], Registrations.City, Registrations.State, Registrations.Zip, Registrations.Country, Registrations.Phone, Registrations.[Alternate Phone], Registrations.[User ID], Registrations.[REG: Registration Type], Accounts.[Account ID], Accounts.[Account ID 18], Accounts.[PS Company Id], IIf(IsNull([Accounts].[Account Name]),1,0) AS Not_Found, IIf([Not_Found]=1,[Manual Account Lookup].[Account Name],[Accounts].[Account Name]) AS FoundAccountName, Registrations.[Current Packages (comma delimited)]
FROM (Registrations LEFT JOIN [Manual Account Lookup] ON Registrations.[Company Name] = [Manual Account Lookup].Company) LEFT JOIN Accounts ON Registrations.[Company Name] = Accounts.[Account Name];