JOIN
JOIN is used to combine rows from two or more tables based on a related column between them. It allows you to extract data from multiple tables and present it as a single result set.
There are several types of JOIN clauses:
- INNER JOIN: Returns only the rows that have matching values in both tables.
- LEFT JOIN: Returns all the rows from the left table and the matching rows from the right table.
- RIGHT JOIN: Returns all the rows from the right table and the matching rows from the left table.
- FULL OUTER JOIN: Returns all the rows from both tables.
Examples
Here are some examples of using JOIN clauses:
sql
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;
