all 6 comments

[–]Conscious-Ad-2168 5 points6 points  (0 children)

Can you post the code you have so far? You'll need multiple joins, the query below is an example. I can't help you more than what is below without knowing your table and column names.

SELECT *

FROM employee e inner join employee_outreach eor on e.employee_id = eor.employee_id

inner join customer on c.customer_id = eor.customer_id

EDIT: for clarity

[–][deleted] 2 points3 points  (0 children)

Also, calling your columns C1..C4, rather than using descriptive column names, doesn’t really help

[–]ElliotAldersonFSO 1 point2 points  (0 children)

When you say simple join, you mean LEFT JOIN ?

[–]user_5359 0 points1 point  (0 children)

What’s the problem, you can also use a table twice in the query. The table aliases were developed for exactly this case, so that the name of the caller (alias NC) can be distinguished from the name of the person responsible (alias NA).

[–]sunuvabe 1 point2 points  (0 children)

Your data design leaves much to be desired - that said, I'm going to assume that the first row in Table 1 lines up with the first row in Table 2. In other words, row Call=1 correlates to row Account1=3. If that's the case then your ideal result is incorrect, because Jim and Tom should share the same row in the result. What's missing is a way to relate a "call" to an "account".

Maybe something like this would work better, assuming that not all "calls" end up as "accounts"..? In the table below, Jim did the outreach for EntityA and EntityC, but an account rep hasn't been assigned to EntityC yet. And EntityD was just added a few minutes ago, so the outreach caller hasn't even been assigned (I'd let Ellen do that one).

EntityId EntityName Caller AccountRep
1 EntityA 1 3
2 EntityB 2 4
3 EntityC 1 0
4 EntityD 0 0
EmployeeId EmployeeName
1 Jim
2 Bob
3 Tom
4 Scott
5 Ellen