Get user from table based on id

Solution 1:

You need two joins to to make this work for you. One join to get to the employee table, and one more join to get to the accounts table.

select d.*, t.id as twap_id, a.account_name
from common.deals_new d 
    left outer join common.twap t on 
        t.deal_id = d.slip_id and
        d.timestamp between '11-11-2021' AND '11-11-2021' and
        d.deal_type in (1, 2) and
        d.quote_id is null
    join employees as e on d.employee_id = e.id
    join accounts as a on a.id = e.account_id 
where d.employee_id is not null
order by d.timestamp desc, d.id
offset 10
limit 10;

Note: I did not fiddle this one, so could have a typo, but I think you get the idea here.