数据库中表的庞杂查询 1、衔接查询 1.0衔接的根本语法格局: from TABLE1 join_type TABLE2 [on (join_condition)][where (query_condition)] TABLE1:左表 TABLE2:右表 join_type:衔接的类型。交叉、内衔接、左外衔接、右外衔接 on:设置衔接条件 where:对衔接查询的成果提高一的挑选 1.1交叉衔接 select * from CUSTOMER cross join ORDERS; 或 select * from CUSTOMER,ORDERS; select c.name,o.order_number from CUSTOMER c,ORDERS o; 1.2内衔接: 隐式内衔接:(不应用on症结字,应用where) select * from CUSTOMER c,ORDERS o where c.id=o.customer_id; 显式内衔接:(应用on症结字) select * from CUSTOMER c inner join ORDERS o on c.id=o.customer_id; 1.3外衔接: 左外衔接:(返回符合衔接条件的所有记载,同时还返回左表中其余的所有记载) select * from CUSTOMER c left outer join ORDERS o on c.id=o.customer_id; 右外衔接:(返回符合衔接条件的所有记载,同时还返回右表中其余的所有记载) select * from CUSTOMER c right outer join ORDERS o on c.id=o.customer_id; 2、子查询(嵌套查询) 子查询: select * from orders where customer_id=(select id from customer where name="张三"); 3、结合查询 SELECT * FROM orders WHERE price>200 UNION SELECT * FROM orders WHERE customer_id=1; 取两条语句的并集,并去除反复的记载。 数据库中表的庞杂查询 1、衔接查询 1.0衔接的根本语法格局: from TABLE1