go
create table t1 (deptid int,uname char(10))
create table t2 (deptid int,memo char(50))
insert into t1 values(1,'John')
insert into t1 values(2,'Tom')
insert into t1 values(3,'Michal')
insert into t2 values(1,'Human Resources Department')
insert into t2 values(2,'General Accounting Department')
insert into t2 values(4,'Engineering Department')
insert into t2 values(5,'Sales Department')
select * from t1 inner join t2 on t1.deptid=t2.deptid
select * from t1 left join t2 on t1.deptid=t2.deptid
select * from t1 right join t2 on t1.deptid=t2.deptid
select * from t1 full join t2 on t1.deptid=t2.deptid
select * from t1 cross join t2
deptid |
uname |
deptid |
memo |
1 |
John |
1 |
Human Resources Department |
2 |
Tom |
2 |
General Accounting Department |
deptid |
uname |
deptid |
memo |
1 |
John |
1 |
Human Resources Department |
2 |
Tom |
2 |
General Accounting Department |
3 |
Michael |
NULL |
NULL |
deptid |
uname |
deptid |
memo |
1 |
John |
1 |
Human Resources Department |
2 |
Tom |
2 |
General Accounting Department |
NULL |
NULL |
4 |
Engineering Department |
NULL |
NULL |
5 |
Sales Department |
deptid |
uname |
deptid |
memo |
1 |
John |
1 |
Human Resources Department |
2 |
Tom |
2 |
General Accounting Department |
NULL |
NULL |
4 |
Engineering Department |
NULL |
NULL |
5 |
Sales Department |
3 |
Michael |
NULL |
NULL |
1 John 2 General Accounting Department
1 John 4 Engineering Department
1 John 5 Sales Department
2 Tom 1 Human Resources Department
2 Tom 2 General Accounting Department
2 Tom 4 Engineering Department
2 Tom 5 Sales Department
3 Michael 1 Human Resources Department
3 Michael 2 General Accounting Department
3 Michael 4 Engineering Department
3 Michael 5 Sales Department