JOIN
JOIN 用于组合两个或多个表中基于相关列的行。 它允许你从多个表中提取数据,并将其呈现为单个结果集。
JOIN 语法有以下类型:
- INNER JOIN:仅返回两个表中具有匹配值的行。
- LEFT JOIN:返回左表中的所有行和右表中的匹配行。
- RIGHT JOIN:返回右表中的所有行和左表中的匹配行。
- FULL OUTER JOIN:返回两个表中的所有行。
示例
下面是使用 JOIN 子句的一些示例:
1. -- Select all rows from the system_metrics table and idc_info table where the idc_id matches
2. SELECT a.*
3. FROM system_metrics a
4. JOIN idc_info b
5. ON a.idc = b.idc_id;
7. -- Select all rows from the idc_info table and system_metrics table where the idc_id matches, and include null values for idc_info without any matching system_metrics
8. SELECT a.*
9. FROM idc_info a
10. LEFT JOIN system_metrics b
11. ON a.idc_id = b.idc;
13. -- Select all rows from the system_metrics table and idc_info table where the idc_id matches, and include null values for idc_info without any matching system_metrics
14. SELECT b.*
15. FROM system_metrics a
16. RIGHT JOIN idc_info b
17. ON a.idc = b.idc_id;
