联合查询 join
the main difference between JOIN and LEFT JOIN lies in how they retrieve data from tables:
- JOIN (INNER JOIN): Returns rows when there is a match in both tables. Excludes rows where there is no match between the tables.
- LEFT JOIN (LEFT OUTER JOIN): Returns all rows from the left table, even if there are no matches in the right table.
示例
假设有两个表:Employees 和 Departments。
Employees 表:
sql+-----------+----------+------------+| EmployeeID | Name | DepartmentID |+-----------+----------+------------+| 1 | Alice | 1 || 2 | Bob | 2 || 3 | Charlie | 3 |+-----------+----------+------------+
Departments 表:
sql+------------+------------+| DepartmentID | DepartmentName |+------------+------------+| 1 | IT || 2 | HR || 4 | Marketing |
