Get emp_no for all non-manager employees
CREATE TABLE `dept_manager` (
`dept_no` char(4) NOT NULL,
`emp_no` int(11) NOT NULL,
`from_date` date NOT NULL,
`to_date` date NOT NULL.PRIMARY KEY (`emp_no`,`dept_no`));
Copy the code
CREATE TABLE `employees` (
`emp_no` int(11) NOT NULL,
`birth_date` date NOT NULL,
`first_name` varchar(14) NOT NULL,
`last_name` varchar(16) NOT NULL,
`gender` char(1) NOT NULL,
`hire_date` date NOT NULL.PRIMARY KEY (`emp_no`));
Copy the code
01 I to answer
An inner join is the intersection of two tables. Select * from B where table A and table B are NULL; select * from B where table A and table B are NULL;
select t1.emp_no
from employees t1
left join dept_manager t2 on t1.emp_no = t2.emp_no
where t2.emp_no is null
Copy the code
02 to you to review
- left join + is NULL
select t1.emp_no
from employees t1
left join dept_manager t2 on t1.emp_no = t2.emp_no
where t2.emp_no is null
Copy the code
- Not IN
select emp_no
from employees
where emp_no not in(select emp_no from dept_manager)
Copy the code
03 Today’s Knowledge
Left JOIN + is NULL not in
Let your mind fly a little longer… 1 question a day, easy to learn.
Day1: brush 1 SQL every day, do not believe the interview you are still hanging on the SQL Day2: brush 1 SQL every day, do not believe the interview you are still hanging on the SQL Day4: brush 1 SQL every day, do not believe the interview you are still hanging on the SQL Day5: Day6: Brush 1 SQL every day, do not believe the interview you are still hanging on SQL Day7: brush 1 SQL every day, do not believe the interview you are still hanging on SQL Day8: brush 1 SQL every day, do not believe the interview you are still hanging on SQL Day9: Brush 1 SQL every day, do not believe the interview you still hang on SQL
Scan the QR code to follow us, 💁 to provide career planning, resume guidance, interview counseling services
The home of data analytics
QQ communication group: 254674155