CROSS JOIN vs INNER JOIN in SQL

前端 未结 12 1063
醉酒成梦
醉酒成梦 2020-11-22 03:16

What is the difference between CROSS JOIN and INNER JOIN?

CROSS JOIN:

SELECT 
    Movies.CustomerID, Movie         


        
12条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 03:39

    Cross join does not combine the rows, if you have 100 rows in each table with 1 to 1 match, you get 10.000 results, Innerjoin will only return 100 rows in the same situation.

    These 2 examples will return the same result:

    Cross join

    select * from table1 cross join table2 where table1.id = table2.fk_id
    

    Inner join

    select * from table1 join table2 on table1.id = table2.fk_id
    

    Use the last method

提交回复
热议问题