sorry
sorry

Reputation: 131

SQL - Difference between using "CROSS JOIN" and ","

is there any difference between writing select * from R,S and select * from R CROSS JOIN S?

Upvotes: 0

Views: 31

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269753

Actually, there is. The issue is semantically how the rest of the query is parsed. So (according to the rules of standard SQL), I don't think the following works:

from a, b join
     c
     on a.x = c.x

The , stops the a from being recognized in the result of the from clause.

However, this does work:

from a cross join b join
     c
     on a.x = c.x

Note: The first version might work in some databases.

Also, I strongly recommend that you never use commas in the FROM clause. This is not about rules. It is about writing clear code and being explicit about how your query is going to combine data from multiple tables.

Upvotes: 2

Related Questions