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

前端 未结 9 1937
庸人自扰
庸人自扰 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 05:06

    If your tables aren't two large, you could create two temp tables in memory and select your content into them in a specific order, and then join them on the row Number.

    e.g.

    CREATE TABLE #Temp_One (
        [RowNum] [int] IDENTITY (1, 1) NOT NULL ,
        [Description] [nvarchar] (50) NOT NULL
    )
    
    CREATE TABLE #Temp_Two (
        [RowNum] [int] IDENTITY (1, 1) NOT NULL ,
        [Description] [nvarchar] (50) NOT NULL
    )
    
    INSERT INTO #Temp_One
    SELECT Your_Column FROM Your_Table_One ORDER BY Whatever
    
    INSERT INTO #Temp_Two
    SELECT Your_Column FROM Your_Table_Two ORDER BY Whatever
    
    SELECT * 
    FROM #Temp_One a 
        LEFT OUTER JOIN #Temp_Two b 
             On a.RowNum = b.RowNum
    

提交回复
热议问题