怎样写这样的SQL句子: 从两个表中各列出部分字段,这两个表没有关系。(100分)

L

lyloyal

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样写这样的SQL句子: 从两个表中各列出部分字段,这两个表没有关系。
例如:表1中有定段:x1,x2;
表2中有字段:y1,y2
需要得出这样的结果集:|x1,y1|,并且以表1为主,x1只出现一次,不重复
(如表1:x1{1,2,3},表2{a,b}:
显示出:x1 y1
1 a
2 b
3
)
 
如果是SQL Server,见下面:(我试过了,没有问题):
drop table #temp1
drop table #temp2
select identity(int,1,1) as no,* into #temp1 From test1
select identity(int,1,1) as no,* into #temp2 From test2
SELECT #temp1.x1, #temp2.y1
FROM #temp2 RIGHT OUTER JOIN
#temp1 ON #temp2.no = #temp1.no

如果是Oracle,就更好办了。因为有个RowNum
 
To xiaoer: 是在Access下,试了一下,不行,thank you!
 
Select x1,y1
From (select distinct x1,(select count(x1)
from (select distinct x1 from 表1)
where x1<=AAA.x1) as tmp
From (select distinct x1 from 表1) AAA
Order by x1) AAA
Left Join
(select distinct y1,(select count(y1)
from (select distinct y1 from 表2)
where y1<=AAA.y1) as tmp
From (select distinct y1 from 表2) AAA
Order by y1) BBB
ON AAA.tmp=BBB.tmp
 
顶部