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

三世轮回 提交于 2019-12-03 04:27:42

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.

A raw cross join is one that has no where clause meaning that one record is produced for every combination of the left and right tables being joined with nulls inserted where there is no left or right side data.

If you add a where clause to a cross join this makes it equivalent to an inner join as the where clause does the same thing as the ON in the inner join.

However, inner joins are generally nicer to use as this separates the ON condition away from the rest of your where clauses making it easier to understand.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!