inner join、 left join 、right join、 outer join语法
时间: 2023-11-25 10:52:27 浏览: 143
SQL 外链接操作小结 inner join left join right join
以下是SQL中inner join、left join、right join、outer join的语法:
1. inner join语法:
```sql
SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name;
```
2. left join语法:
```sql
SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;
```
3. right join语法:
```sql
SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name = table2.column_name;
```
4. outer join语法:
```sql
SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table1.column_name = table2.column_name;
```
其中,inner join返回两个表中联结字段相等的行,left join返回包括左表中的所有记录和右表中联结字段相等的记录,right join返回包括右表中的所有记录和左表中联结字段相等的记录,outer join返回两个表中联结字段相等的行以及未联结的行。
阅读全文