SELECT
a.CustomerEmail,
a.CustomerName,
a.SalespersonID,
b.SalespersonEmail
FROM CustomerTable a
LEFT JOIN SalespersonTable b
ON a.SalespersonID = b.SalespersonID
AND
SELECT
a.CustomerEmail,
a.CustomerName,
a.SalespersonID,
b.SalespersonEmail
FROM CustomerTable a
INNER JOIN SalespersonTable b
ON a.SalespersonID = b.SalespersonID
I have tried LEFT JOIN and INNER JOIN but both are not producing correct results.
Thanks for your help, just for my understanding what AND a.CustomerName = a.CustomerName will do by adding in the inner join? Does that mean we I want additional columns fill Customer table, I'll be to add in SELECT & INNER JOIN, both?
declare @SalespersonTable table (SalespersonID int , SalespersonEmail varchar(20))
insert into @SalespersonTable Values
(101,'sp1@domain.com')
,(102,'sp2@domain.com')
,(103,'sp3@domain.com')
,(104,'sp4@domain.com')
SELECT
a.CustomerEmail
, a.CustomerName
, a.SalespersonID
, b.SalespersonEmail
FROM
@CustomerTable a
LEFT JOIN
@SalespersonTable b
ON a.SalespersonID = b.SalespersonID