SQL连接查询(JOIN)

SQL连接查询(JOIN)

主要列举这个图:
SQL连接查询(JOIN)_第1张图片

INNER JOIN

SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name=table2.column_name;

或者,

SELECT column_name(s)
FROM table1
JOIN table2
ON table1.column_name=table2.column_name;

SQL连接查询(JOIN)_第2张图片

LEFT JOIN

SQL连接查询(JOIN)_第3张图片

SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name=table2.column_name;

或者,

SELECT column_name(s)
FROM table1
LEFT OUTER JOIN table2
ON table1.column_name=table2.column_name;

RIGHT JOIN

SQL连接查询(JOIN)_第4张图片
同理,

SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name=table2.column_name;

或者,

SELECT column_name(s)
FROM table1
LEFT OUTER JOIN table2
ON table1.column_name=table2.column_name;

FULL OUTER JOIN

SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table1.column_name=table2.column_name;
```![在这里插入图片描述](https://img-blog.csdnimg.cn/20190404134555374.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpYWJlbnNodQ==,size_16,color_FFFFFF,t_70)

# 简单举个left join的例子1![在这里插入图片描述](https://img-blog.csdnimg.cn/20190404134727702.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpYWJlbnNodQ==,size_16,color_FFFFFF,t_70)2![在这里插入图片描述](https://img-blog.csdnimg.cn/20190404134739446.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpYWJlbnNodQ==,size_16,color_FFFFFF,t_70)
查询结果,
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190404134807685.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpYWJlbnNodQ==,size_16,color_FFFFFF,t_70)

你可能感兴趣的:(SQL连接查询(JOIN))