Karunakar
Karunakar

Reputation: 2349

How to find departments which has no employees without using nested query?

I have two tables:

employee(e_id,e_name,d_id),department(d_id,d_name)

my query is:

select d.d_name from department d where d.d_id not in (
select distinct e.d_id from employee e);

is there any alternative way to do this?.

Upvotes: 0

Views: 480

Answers (1)

NMK
NMK

Reputation: 1020

Try this.

   select department.* from department
     left join employee
       on  employee.d_id = department.d_id
     where employee.d_id is null

Upvotes: 1

Related Questions