Correct way to select from two tables in SQL Server with no common field to join on

后端 未结 3 1576
Happy的楠姐
Happy的楠姐 2020-12-25 11:04

Back in the old days, I used to write select statements like this:

SELECT 
table1.columnA, table2.columnA

FROM
table1, table2

WHERE
table1.columnA = \'Some         


        
3条回答
  •  独厮守ぢ
    2020-12-25 11:59

    You can (should) use CROSS JOIN. Following query will be equivalent to yours:

    SELECT 
       table1.columnA
     , table2.columnA
    FROM table1 
    CROSS JOIN table2
    WHERE table1.columnA = 'Some value'
    

    or you can even use INNER JOIN with some always true conditon:

    FROM table1 
    INNER JOIN table2 ON 1=1
    

提交回复
热议问题