多表的查询
程序员文章站
2022-05-29 22:05:40
...
1.1 交叉连接:(cross join)
返回多表的记录的笛卡尔积。(第一张表:5 第二章表:7,返回5*7=35)
select c.ID,c.NAME,o.ORDER_NUMBER,o.price from CUSTOMER c cross join ORDERS o;
1.2 内连接(inner join)
1)隐式内连接:
select * from CUSTOMER c,ORDERS o where c.ID=o.CUSTOMER_id;
2)显式内连接:
select * from CUSTOMER c inner join ORDERS o on c.Id=o.CUSTOMER_id;
1.3 外连接(outer join)
1)左外连接 (LEFT OUTER JOIN) 也叫左连接(LEFT JOIN)
返回满足连接条件的记录,同时返回左表中剩余的其他记录。
select * from CUSTOMER c left outer join ORDERS o on c.ID=o.CUSTOMER_ID;
2)右外连接 (RIGHT OUTER JOIN) 也叫右连接(RIGHT JOIN)
返回满足连接条件的记录,同时返回右表中剩余的其他记录。
select * from CUSTOMER c right outer join ORDERS o on c.ID=o.CUSTOMER_ID;
1.4 全连接(Full Join)
MYSQL中不支持full join 会报1064的错误
上一篇: Python内置的常用函数
下一篇: 源生JS怎样实现todolist功能