0

I have 3 tables employee, sales, department

Employee table

------------------------------
  AssignemtID | EmployeeEmail
-------------------------------
      1       | abc.@cam.com
-------------------------------
      2       | bdc@cam.com
-----------------------------
      3       | dgs@cam.com
-----------------------------
      4       | tyr@cam.com
------------------------------

Sales table

Sales | EmployeeEmail     | Emp ID
------------------------------------
24333  | abc.@cam.com  |  34
------------------------------------
46373 | bdc@cam.com    | 24
-----------------------------------
32212 | dgs@cam.com    | 78
-----------------------------------

Department table

Department | Sales       |Emp ID
-------------------------------
AS         | 24333       |34
-------------------------------
we         | 46373       |24
-----------------------------
de         | 32212       |78
------------------------------

I want to see all the employee who are there in the Employee table but not in the Department table. the data is huge in all the 3 tables

Barmar
  • 741,623
  • 53
  • 500
  • 612
Sandy
  • 1
  • 1

1 Answers1

0

You can connect Employee to Department by joining it with Sales.

SELECT *
FROM Employee
WHERE EmployeeEmail NOT IN (
    SELECT EmployeeEmail
    FROM Sales AS s
    JOIN Department AS d ON s.Sales = d.Sales
)

or

SELECT e.*
FROM Employee AS e
LEFT JOIN Sales AS s ON s.EmployeeEmail = e.EmployeeEmail
LEFT JOIN Department AS d ON s.Sales = d.Sales
WHERE d.Department IS NULL
Barmar
  • 741,623
  • 53
  • 500
  • 612