数据库多表查询
多表查询
连接
既然是多表查询不可避免就会用到多个表的数据。
- From连接多表
如下连接了AB两个表
1 | select ...... |
自连接
内连接 inner join
外连接
- left join
1
2
3
4select ......
from A
left join B
on XXXX- right join
1
2
3
4select ......
from A
right join B
on XXXXX- full join
1
2
3
4select .....
from A
full join B
on XXXXXX
嵌套子查询
及查询过程中内嵌一个查询
- in
如果A的过滤条件需要用到另外一张表的数据。
1 | select * |
- exists
上方in等价,个人觉得适用于多过滤条件的情况
1 | select * |
Others
别名
简化查询过程(如果表名称比较长)
如
1 | select * |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 理想三巡!