In SQL, what's the difference between JOIN and CROSS JOIN?

后端 未结 3 431
伪装坚强ぢ
伪装坚强ぢ 2021-02-06 05:36

What\'s the difference between:

select t1.a1, t1.a2, t1.a3 from t1 cross join t2 where t1.a3 = t2.a1

and:

select t1.a1, t1.a2,          


        
3条回答
  •  难免孤独
    2021-02-06 06:11

    There's no difference, although one can smile about it a little. You make a cross join first and with the where clause you convert it to an inner join (at least with the first one). This way of writing joins is more than 20 years old and kind of error prone in complex statements. I'd recommend to use the new funky way of writing it like this:

    select t1.a1, t1.a2, t1.a3 
    from t1 
    inner join t2 on t1.a3 = t2.a1
    

提交回复
热议问题