How to join two tables together with same number of rows by their order

前端 未结 9 1985
庸人自扰
庸人自扰 2020-12-19 04:38

I am using SQL2000 and I would like to join two table together based on their positions

For example consider the following 2 tables:

table1
-------
name
-         


        
9条回答
  •  生来不讨喜
    2020-12-19 04:56

    Absolutely. Use the following query but make sure that (order by) clause uses the same columns the order of rows will change which you dont want.

    select
    (
    row_number() over(order by name) rno, * from Table1
    ) A  
    (
    row_number() over(order by name) rno, * from Table2
    ) B
    JOIN A.rno=B.rno
    

    order by clause can be modified according to user linkings

    The above query produces unique row_numbers for each row, which an be joined with row_numbers of the other table

提交回复
热议问题