SQL中的连接可以分为内连接,外连接,以及交叉连接 . 1. 交叉连接CROSS JOIN 如果不带WHERE条件子句,它将会返回被连接的两个表的笛卡尔积,返回结果的行数等于两个表行数的乘积: 举例,下列A.B.C 执行结果相同,但是效率不一样: A:SELECT * FROM table1 CROSS JOIN table2 B:SELECT * FROM table1,table2 C:select * from table1 a inner join table2 b A:select a
1 常用表联结(inner join,left join,right join,full join,cross join) if object_id(N'table1',N'U') is not null drop table table1 if object_id(N'table2',N'U') is not null drop table table2 )) insert into table1 ,'小明' union all ,'小李' union all ,'小陈' union all
SQL中的连接可以分为内连接,外连接,以及交叉连接 . 1. 交叉连接CROSS JOIN 如果不带WHERE条件子句,它将会返回被连接的两个表的笛卡尔积,返回结果的行数等于两个表行数的乘积: 举例,下列A.B.C 执行结果相同,但是效率不一样: A:SELECT * FROM table1 CROSS JOIN table2 B:SELECT * FROM table1,table2 C:select * from table1 a inner join table2 b A:select a
测试数据脚本 CREATE TABLE Atable ( S# INT, Sname ), Sage INT, Sfrom ) ) insert into Atable ,N,N'A' union all ,N, N'A' union all ,N,N'A' union all ,N,N'A' CREATE TABLE Btable ( S# INT, Sname ), Sage INT, Sfrom ) ) insert into Btable ,N,N'B' union all ,N,N'B
Set up the Workbook In this example, there are two tables -- Raw Materials and Packaging -- and each table is on a separate worksheet. The Raw Materials table is on the sheet named Materials, and the Packaging table is on the sheet named Packaging. T
FULL JOIN 只要其中某个表存在匹配,FULL JOIN 关键字就会返回行.(返回JOIN 两端表的所有数据,无论其与另一张表有没有匹配.显示左连接.右连接和内连接的并集) FULL JOIN 关键字语法 SELECT column_name(s) FROM table_name1 FULL JOIN table_name2 ON table_name1.column_name=table_name2.column_name 注释:在某些数据库中, FULL JOIN 称为 FULL OU
表t_a id name 1 a1 2 a2 表t_b a1_id name num 2 b2 1 3 b3 100 left join 后加查询条件 select a.* from t_a a left join t_b b on a.id=b.a1_id and b.num>10 where 1=1 结果:2条数据 where后面加查询条件 select a.* from t_a a left join t_b b on a.id=b.a1_id where b.num>10 结果1条数据