5.4 自连接
MySQL自连接的例子
SELECT
CONCAT(m.lastname, ', ', m.firstname) AS 'Manager',
CONCAT(e.lastname, ', ', e.firstname) AS 'Direct report'
FROM
employees e
INNER JOIN
employees m ON m.employeeNumber = e.reportsto
ORDER BY manager;+--------------------+--------------------+
| Manager | Direct report |
+--------------------+--------------------+
| Bondur, Gerard | Jones, Barry |
| Bondur, Gerard | Castillo, Pamela |
| Bondur, Gerard | Bondur, Loui |
| Bondur, Gerard | Bott, Larry |
| Bondur, Gerard | Gerard, Martin |
| Bondur, Gerard | Hernandez, Gerard |
| Bow, Anthony | Vanauf, George |
| Bow, Anthony | Patterson, Steve |
| Bow, Anthony | Thompson, Leslie |
| Bow, Anthony | Tseng, Foon Yue |
| Bow, Anthony | Firrelli, Julie |
| Bow, Anthony | Jennings, Leslie |
| Murphy, Diane | Firrelli, Jeff |
| Murphy, Diane | Patterson, Mary |
| Nishi, Mami | Kato, Yoshimi |
| Patterson, Mary | Bow, Anthony |
| Patterson, Mary | Patterson, William |
| Patterson, Mary | Bondur, Gerard |
| Patterson, Mary | Nishi, Mami |
| Patterson, William | Marsh, Peter |
| Patterson, William | King, Tom |
| Patterson, William | Fixter, Andy |
+--------------------+--------------------+
22 rows in setLast updated