select a.id as 'id1',b.id as 'id2' from 表A a ,表B b
create table A(id int) insert into A select 1 insert into A select 2create table B(id int) insert into B select 3 insert into B select 4select * from A,B /*1 3 1 4 2 3 2 4*/select * from A,B order by B.id,A.id/* 1 3 2 3 1 4 2 4*/drop table A,B
select a.id as 'id1',b.id as 'id2'
from 表A a ,表B b
create table A(id int)
insert into A select 1
insert into A select 2create table B(id int)
insert into B select 3
insert into B select 4select * from A,B
/*1 3
1 4
2 3
2 4*/select * from A,B order by B.id,A.id/*
1 3
2 3
1 4
2 4*/drop table A,B
============
笛卡儿乘积是一张表的行数乘以另一张表的行数.
在离散数学和数据库之中大量用到!
设关系R和S的元组字节数分别是IR和IS,元组数目分别是TR和TS,则笛卡儿乘积R×S的元组字节数是IR+IS,元组数目是TRTS,空间字节数是TRTS(IR+IS).
一样的
create table #a(id int)
create table #b(id int)insert into #a values(1)insert into #a values(2)insert into #b values(3)insert into #b values(4)select a.id,b.id from #a a cross join #b bid id
----------- -----------
1 3
2 3
1 4
2 4(4 行受影响)
[ID]=a.ID,
[ID2]=b.ID
from
a
join
b on 1=1
order by b.ID asc,a.ID