我要说tableA
col1
和tableB
col2
,其Table A
---------
A
B
C
D
Table B
---------
1
2
3
4
内容如下:
A, 1
B, 2
C, 3
D, 4
我想要一个返回给我的select语句:
Select tableA.col1, tableB.col2 from tableA, tableB
我试过这个电话:
A, 1
B, 1
C, 1
D, 1
A, 2
..
..
etc
但它返回以下内容:
A, 1
B, 2
C, 3
D, 4
我怎样才能把它拉回来:
{{1}}
答案 0 :(得分:3)
试试这个:
select b.val1, b.val1, c.val2 from tableA a
inner join (select ROW_NUMBER() OVER () AS RowNumber, col1 as val1 from tableA) on a.col1 = b.val1
inner join (select ROW_NUMBER() OVER () AS RowNumber, col2 as val2 from tableB) c on c.RowNumber = b.RowNumber