0

I noticed on some test data that queries of the form

SELECT *
FROM a
JOIN b ON a.x = b.y
WHERE [more conditions...];

were returning the same data as queries of the form

SELECT *
FROM a,b
WHERE a.x = b.y
AND [more conditions...];

Intuitively they seem equivalent, but I'm not confident that this is the case.

I prefer the query that uses JOIN as it separates the general structure of the query from the specific business logic of the query. i.e. The conditions in the WHERE section of the query using JOIN are ones that could be parameterized.

In which other ways, if any, are these queries not identical?

vowel-house-might
  • 1,686
  • 14
  • 18

4 Answers4

1

These queries are logically identical. The logical differences between the new JOIN form (SQL-92) and the older , form are in how the outer join expressions work.

Where they are not identical is in code quality. The SQL-89 form was superceeded by the SQL-92 over 20 years ago, and the newer form is much preferred for its clarity, better standards adoption for outer joins and greater expressive power for outer joins.

RBarryYoung
  • 55,398
  • 14
  • 96
  • 137
1

The general answer is yes.

However, you have to consider that with the complexity of your SQL statements, the complexity to parse them and determine their execution plan in the database will increase, making it more likely that ANSI style joins and regular joins don't have the same execution plan, performance and output.

This is certainly the case in Oracle, which has some serious bugs still in their ANSI join parsing (have a bugs few pending with Oracle support).

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
1

Both forms are equivalent but another reason why

SELECT *
FROM a
JOIN b ON a.x = b.y
WHERE [more conditions...];

is often preferred is that it offers more flexibility if you need to filter things a bit differently. Imagine for instance that x may be null. You have just to change the type of join to left join.

M. Page
  • 2,694
  • 2
  • 20
  • 35
0

Yes, those two ways function in similar manner, according to the book: Fundamentals of database systems / Ramez Elmasri, Shamkant B. Navathe. Online book link

jyrkim
  • 2,849
  • 1
  • 24
  • 33