Find the last_name and first_name of all employees and the corresponding department number dept_no, including employees who have not been assigned a specific department for the time being [5]

Title description

Find all employees last_name and first_name and the corresponding department number dept_no, including temporary employees are not assigned specific sectors (please note that the output before and after the order described in the respective columns)
the CREATE TABLE `dept_emp` (
` emp_no` int (11) the NOT NULL,
dept_no` char `(. 4) the NOT NULL,
` from_date` DATE the NOT NULL,
`to_date` DATE the NOT NULL,
a PRIMARY KEY (emp_no``, `dept_no`));
the 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`));

Enter description:

no

Output description:

last_name first_name dept_no
Facello Georgi d001
abridgement abridgement abridgement
Lock Mary NULL (empty here in sqlite, NULL for MySQL)
select e.last_name,e.first_name,d.dept_no
from employees e
left join dept_emp d
on e.emp_no=d.emp_no

 

Guess you like

Origin blog.csdn.net/gjs935219/article/details/109194697