Is CROSS JOIN a synonym for INNER JOIN without ON clause?

前端 未结 2 508
再見小時候
再見小時候 2020-12-30 20:37

I am wondering whether CROSS JOIN can be safely replaced with INNER JOIN in any query when it is found.

Is an INNER JOIN witho

2条回答
  •  青春惊慌失措
    2020-12-30 21:25

    In all modern databases all these constructs are optimized to the same plan.

    Some databases (like SQL Server) require an ON condition after the INNER JOIN, so your third query just won't parse there.

    Visibility scope of the tables is in the JOIN order, so this query:

    SELECT  *
    FROM    s1
    JOIN    s2
    ON      s1.id IN (s2.id, s3.id)
    CROSS JOIN
            s3
    

    won't parse, while this one:

    SELECT  *
    FROM    s2
    CROSS JOIN
            s3
    JOIN    s1
    ON      s1.id IN (s2.id, s3.id)
    

    will.

提交回复
热议问题