CROSS JOIN vs INNER JOIN in SQL

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

What is the difference between CROSS JOIN and INNER JOIN?

CROSS JOIN:

SELECT 
    Movies.CustomerID, Movie         


        
12条回答
  •  猫巷女王i
    2020-11-22 03:33

    A = {1,5,3,4,6,7,9,8} B = {2,8,5,4,3,6,9}

    cross join act as Cartesian product A ✖ B = {1,2}, {1,8}...,{5,2}, {5,8},{5,5}.....{3,3}...,{6,6}....{8,9} and returned this long result set..

    when processing inner join its done through Cartesian product and choose matching pairs.. if think this ordered pairs as two table's primary keys and on clause search for A = B then inner join choose {5,5}, {4,4}, {6,6}, {9,9} and returned asked column in select clause related to these id's.

    if cross join on a = b then it's result same result set as inner join. in that case also use inner join.

提交回复
热议问题