Home > Blockchain >  Why doesn't this query to show employees that aren't managers work?
Why doesn't this query to show employees that aren't managers work?

Time:11-30

Wrote this MySQL query to show all employees that aren't managers:

SELECT empno
FROM emp
WHERE empno NOT IN (SELECT mgr FROM emp); 

but it shows no results. What could be the problem? This is the table.

CREATE TABLE emp (
  empno int NOT NULL default 0000,
  ename char(10) default NULL,
  job char(9) default NULL,
  mgr int default NULL,
  hiredate datetime default NULL,
  sal double default NULL,
  comm double default NULL,
  deptno int default NULL,
  PRIMARY KEY (empno)
);

CodePudding user response:

SELECT empno
FROM emp
WHERE empno NOT IN (SELECT mgr FROM emp WHERE mgr IS NOT NULL) ;
  • Related