Vous êtes sur la page 1sur 5

mysql> select department_id, department_name, location_id, city

-> from departments


-> natural join locations;
+---------------+-----------------+-------------+---------------------+
| department_id | department_name | location_id | city |
+---------------+-----------------+-------------+---------------------+
| 10 | Administration | 1700 | Seattle |
| 20 | Marketing | 1800 | Toronto |
| 50 | Shipping | 1500 | South San Francisco |
| 60 | IT | 1400 | Southlake |
| 80 | Sales | 2500 | Oxford |
| 90 | Executive | 1700 | Seattle |
| 110 | Accounting | 1700 | Seattle |
| 190 | Contracting | 1700 | Seattle |
+---------------+-----------------+-------------+---------------------+
8 rows in set (0.99 sec)
mysql> select employee_id
-> from employees;
+-------------+
| employee_id |
+-------------+
| 33 |
| 44 |
| 55 |
| 100 |
| 101 |
| 102 |
| 103 |
| 104 |
| 107 |
| 124 |
| 141 |
| 142 |
| 143 |
| 144 |
| 149 |
| 174 |
| 176 |
| 178 |
| 200 |
| 201 |
| 202 |
| 205 |
| 206 |
| 207 |
+-------------+
24 rows in set (0.13 sec)
mysql> select employee_id, department_id, city, name
-> from departments
-> natural join departments;
ERROR 1066 (42000): Not unique table/alias: 'departments'
mysql> select employee_id, department_id, city, name
-> from employees
-> natural join department_id;
ERROR 1146 (42S02): Table 'dbrh.department_id' doesn't exist
mysql> select employee_id, department_id, city, name
-> from departments
-> natural join location, departments;
ERROR 1066 (42000): Not unique table/alias: 'departments'
mysql> select employee_id, department_id, city, name
-> from employees
-> natural join department, location;
ERROR 1146 (42S02): Table 'dbrh.department' doesn't exist
mysql> select employee_id, department_id, city, name
-> from departments
-> natural join locations;
ERROR 1054 (42S22): Unknown column 'employee_id' in 'field list'
mysql> select employee_id, department_id, city, name
-> from employees
-> natural join employee_id;
ERROR 1146 (42S02): Table 'dbrh.employee_id' doesn't exist
mysql> select employee_id, department_id, city, name
-> from employees
-> natural join locations
-> natural join employees;
ERROR 1066 (42000): Not unique table/alias: 'employees'
mysql> select employee_id, department_id, city, name
-> from employees
-> natural join locations,
-> natural join employees;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'natur
al join employees' at line 4
mysql> select employee_id, name, department_name, city
-> from employees
-> natural join locations
-> natural join departments;
ERROR 1054 (42S22): Unknown column 'name' in 'field list'
mysql> select employee_id, department_name, city
-> from employees
-> natural join locations,
-> natural join departments;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'natur
al join departments' at line 4
mysql> select employee_id, department_name, city
-> from employees
-> natural join locations
-> natural join departments;
+-------------+-----------------+---------------------+
| employee_id | department_name | city |
+-------------+-----------------+---------------------+
| 101 | Executive | Seattle |
| 102 | Executive | Seattle |
| 104 | IT | Southlake |
| 107 | IT | Southlake |
| 141 | Shipping | South San Francisco |
| 142 | Shipping | South San Francisco |
| 143 | Shipping | South San Francisco |
| 144 | Shipping | South San Francisco |
| 174 | Sales | Oxford |
| 176 | Sales | Oxford |
| 202 | Marketing | Toronto |
| 206 | Accounting | Seattle |
+-------------+-----------------+---------------------+
12 rows in set (0.03 sec)
mysql> select employee_id, department_name, city, last_name
-> from employees
-> natural join locations
-> natural join departments;
+-------------+-----------------+---------------------+-----------+
| employee_id | department_name | city | last_name |
+-------------+-----------------+---------------------+-----------+
| 101 | Executive | Seattle | Kochhar |
| 102 | Executive | Seattle | De Haan |
| 104 | IT | Southlake | Ernst |
| 107 | IT | Southlake | Lorentz |
| 141 | Shipping | South San Francisco | Rajs |
| 142 | Shipping | South San Francisco | Davies |
| 143 | Shipping | South San Francisco | Matos |
| 144 | Shipping | South San Francisco | Vargas |
| 174 | Sales | Oxford | Abel |
| 176 | Sales | Oxford | Taylor |
| 202 | Marketing | Toronto | Fay |
| 206 | Accounting | Seattle | Gietz |
+-------------+-----------------+---------------------+-----------+
12 rows in set (0.00 sec)
mysql> e.employee_id, e.last_name, e.department_id,
-> d.department_id, d.location_id
-> from employees e JOIN departments d
-> ON (e.department_id = d.department_id);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'e.emp
loyee_id, e.last_name, e.department_id,
d.department_id, d.location_id
from' at line 1
mysql> select e.employee_id, e.last_name, e.department_id,
-> d.department_id, d.location_id
-> from employees e JOIN departments d
-> ON (e.department_id = d.department_id);
+-------------+------------+---------------+---------------+-------------+
| employee_id | last_name | department_id | department_id | location_id |
+-------------+------------+---------------+---------------+-------------+
| 33 | De la Mora | 2 | 2 | NULL |
| 44 | De la Rosa | 2 | 2 | NULL |
| 55 | Gomez | 2 | 2 | NULL |
| 100 | King | 90 | 90 | 1700 |
| 101 | Kochhar | 90 | 90 | 1700 |
| 102 | De Haan | 90 | 90 | 1700 |
| 103 | Hunold | 60 | 60 | 1400 |
| 104 | Ernst | 60 | 60 | 1400 |
| 107 | Lorentz | 60 | 60 | 1400 |
| 124 | Mourgos | 50 | 50 | 1500 |
| 141 | Rajs | 50 | 50 | 1500 |
| 142 | Davies | 50 | 50 | 1500 |
| 143 | Matos | 50 | 50 | 1500 |
| 144 | Vargas | 50 | 50 | 1500 |
| 149 | Zlotkey | 80 | 80 | 2500 |
| 174 | Abel | 80 | 80 | 2500 |
| 176 | Taylor | 80 | 80 | 2500 |
| 178 | Grant | 2 | 2 | NULL |
| 200 | Whalen | 10 | 10 | 1700 |
| 201 | Hartstein | 20 | 20 | 1800 |
| 202 | Fay | 20 | 20 | 1800 |
| 205 | Higgins | 110 | 110 | 1700 |
| 206 | Gietz | 110 | 110 | 1700 |
+-------------+------------+---------------+---------------+-------------+
23 rows in set (0.00 sec)
mysql> select employee_id, city, department_name
-> from employees e
-> join departments d
-> on d.department_id = e.department_id
-> join locations l
-> on d.location_id = l.location_id;
+-------------+---------------------+-----------------+
| employee_id | city | department_name |
+-------------+---------------------+-----------------+
| 100 | Seattle | Executive |
| 101 | Seattle | Executive |
| 102 | Seattle | Executive |
| 103 | Southlake | IT |
| 104 | Southlake | IT |
| 107 | Southlake | IT |
| 124 | South San Francisco | Shipping |
| 141 | South San Francisco | Shipping |
| 142 | South San Francisco | Shipping |
| 143 | South San Francisco | Shipping |
| 144 | South San Francisco | Shipping |
| 149 | Oxford | Sales |
| 174 | Oxford | Sales |
| 176 | Oxford | Sales |
| 200 | Seattle | Administration |
| 201 | Toronto | Marketing |
| 202 | Toronto | Marketing |
| 205 | Seattle | Accounting |
| 206 | Seattle | Accounting |
+-------------+---------------------+-----------------+
19 rows in set (0.00 sec)
mysql> select e.employee_id, city, department_name, last_name, region_name, coun
try_name, start_date, end_date
-> from employees e
-> JOIN departments d
-> ON d.department_id = e.department_id
-> JOIN locations l
-> ON d.location_id = l.location_id
-> JOIN countries c
-> ON c.country_id = l.country_id
-> JOIN regions r
-> ON r.region_id = c.region_id
-> JOIN job_history j
-> ON j.department_id = d.department_id;
+-------------+---------------------+-----------------+-----------+-------------
+--------------------------+------------+------------+
| employee_id | city | department_name | last_name | region_name
| country_name | start_date | end_date |
+-------------+---------------------+-----------------+-----------+-------------
+--------------------------+------------+------------+
| 100 | Seattle | Executive | King | Americas
| United States of America | 1987-09-17 | 1993-06-17 |
| 100 | Seattle | Executive | King | Americas
| United States of America | 1994-07-01 | 1998-12-31 |
| 101 | Seattle | Executive | Kochhar | Americas
| United States of America | 1987-09-17 | 1993-06-17 |
| 101 | Seattle | Executive | Kochhar | Americas
| United States of America | 1994-07-01 | 1998-12-31 |
| 102 | Seattle | Executive | De Haan | Americas
| United States of America | 1987-09-17 | 1993-06-17 |
| 102 | Seattle | Executive | De Haan | Americas
| United States of America | 1994-07-01 | 1998-12-31 |
| 103 | Southlake | IT | Hunold | Americas
| United States of America | 1993-01-13 | 1998-07-24 |
| 104 | Southlake | IT | Ernst | Americas
| United States of America | 1993-01-13 | 1998-07-24 |
| 107 | Southlake | IT | Lorentz | Americas
| United States of America | 1993-01-13 | 1998-07-24 |
| 124 | South San Francisco | Shipping | Mourgos | Americas
| United States of America | 1998-03-24 | 1999-12-31 |
| 124 | South San Francisco | Shipping | Mourgos | Americas
| United States of America | 1999-01-01 | 1999-12-31 |
| 141 | South San Francisco | Shipping | Rajs | Americas
| United States of America | 1998-03-24 | 1999-12-31 |
| 141 | South San Francisco | Shipping | Rajs | Americas
| United States of America | 1999-01-01 | 1999-12-31 |
| 142 | South San Francisco | Shipping | Davies | Americas
| United States of America | 1998-03-24 | 1999-12-31 |
| 142 | South San Francisco | Shipping | Davies | Americas
| United States of America | 1999-01-01 | 1999-12-31 |
| 143 | South San Francisco | Shipping | Matos | Americas
| United States of America | 1998-03-24 | 1999-12-31 |
| 143 | South San Francisco | Shipping | Matos | Americas
| United States of America | 1999-01-01 | 1999-12-31 |
| 144 | South San Francisco | Shipping | Vargas | Americas
| United States of America | 1998-03-24 | 1999-12-31 |
| 144 | South San Francisco | Shipping | Vargas | Americas
| United States of America | 1999-01-01 | 1999-12-31 |
| 149 | Oxford | Sales | Zlotkey | Europe
| United Kingdom | 1998-03-24 | 1998-12-31 |
| 149 | Oxford | Sales | Zlotkey | Europe
| United Kingdom | 1999-01-01 | 1999-12-31 |
| 174 | Oxford | Sales | Abel | Europe
| United Kingdom | 1998-03-24 | 1998-12-31 |
| 174 | Oxford | Sales | Abel | Europe
| United Kingdom | 1999-01-01 | 1999-12-31 |
| 176 | Oxford | Sales | Taylor | Europe
| United Kingdom | 1998-03-24 | 1998-12-31 |
| 176 | Oxford | Sales | Taylor | Europe
| United Kingdom | 1999-01-01 | 1999-12-31 |
| 201 | Toronto | Marketing | Hartstein | Americas
| Canada | 1996-02-17 | 1999-12-19 |
| 202 | Toronto | Marketing | Fay | Americas
| Canada | 1996-02-17 | 1999-12-19 |
| 205 | Seattle | Accounting | Higgins | Americas
| United States of America | 1989-09-21 | 1993-10-27 |
| 205 | Seattle | Accounting | Higgins | Americas
| United States of America | 1993-10-28 | 1997-03-15 |
| 206 | Seattle | Accounting | Gietz | Americas
| United States of America | 1989-09-21 | 1993-10-27 |
| 206 | Seattle | Accounting | Gietz | Americas
| United States of America | 1993-10-28 | 1997-03-15 |
+-------------+---------------------+-----------------+-----------+-------------
+--------------------------+------------+------------+
31 rows in set (0.07 sec)
mysql>

Vous aimerez peut-être aussi