November 2, 2011 at 9:07 am
SELECT Distinct COMPANY = t1.COMPANY, NAME = t1.NAME, Phone = t1.Phone, Email = t1.Email
FROM Process.dbo.world_event t1
JOIN Customers.dbo.lead t2
ON t1.COMPANY = t2.COMPANY
ORDER BY COMPANY
I'm stuck. I imported an excel spreadsheet with NAME and COMPANY and created a column for phone and email. I'd like to pull in Phone and email from another table if the info matches one of the names on my spreadsheet.
I tried this too and recieved mulitples of the same name but different email addresses.
Select Distinct dbo.world_event.Name, dbo.world_event.COMPANY, customers.dbo.lead.Phone, customers.dbo.lead.Email
FROM dbo.world_event
LEFT JOIN customers.dbo.lead
ON dbo.world_event.COMPANY = customers.dbo.lead.COMPANY
Any help would be greatly appreciated.
November 2, 2011 at 9:24 am
It sounds like you have multiple entities in the leads table that match each name. Do you have another field you can use in your join?
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
November 2, 2011 at 9:54 am
I added the Id from the leads table. Since the IDs are different but the names are the same it makes me think that the users created multiple leads for the same person.
November 2, 2011 at 10:04 am
littlelisa1111 (11/2/2011)
I added the Id from the leads table. Since the IDs are different but the names are the same it makes me think that the users created multiple leads for the same person.
When dealing with leads - that is a very common thing to happen. It is a good idea to have a matching process run in the background to dedupe leads and merge any that are matches.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
November 20, 2011 at 4:57 pm
Another approach could be to alter the definition of the current table that holds the email addresses and add an Id column to store the Primary Key Id field from the table holding the Name and Company values and create a Foreign Key relationship between the 2 tables instead of duplicating the data.
It depends how you want to handle it from here. Do you want a One(lead)-To-Many(email addresses) or do you want a One(lead)-To-One(email address) relationship? That will be determined by what makes a record unique. Is it Name, Company? Or is it Name, Company and Email? This determines how you will set up the constraints for referential integrity and data integrity to ensure you don't allow duplicates.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply