I have the following table setups:
//clients
+-----------+----------+------------+
| Id | Client | Status |
+-----------+----------+------------+
| 1 | A | Active |
| 2 | B | Active |
| 3 | C | Inactive |
+-----------+----------+------------+
//manager Table
+-----------+----------+
| clientId | managerId|
+-----------+----------+
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
+-----------+----------+
//users table
+-----------+----------+
| id | firstName|
+-----------+----------+
| 1 | Carrera |
| 2 | Taylor |
| 3 | Diaz |
+-----------+----------+
//Desired Output
+-----------+----------+
| clientId | managerId|
+-----------+----------+
| 1 | 2 |
| 1 | 3 |
| 2 | 1 |
| 2 | 3 |
+-----------+----------+
How can I write a query to get the desired output? I have tried something like this but the output is not desired:
select c.id as "Client"
, u.id as "user"
from managers cm
left
join users u
on u.id = cm.managerId
left
join clients c
on c.id = cm.clientId
where cm.managerId not in (select id from users where firstName like '%a%')
and cm.clientId not in (select id from clients where status = 'Active');