32

I have two select join SQL statements:

select a.id from table_a as a, table_b as b where a.id=b.id;
select a.id from table_a as a inner join table_b as b on a.id=b.id;

Obviously, they are the same in result. But is there any difference between them , such as performance, portability.

Ned Batchelder
  • 364,293
  • 75
  • 561
  • 662
爱国者
  • 4,298
  • 9
  • 47
  • 66

4 Answers4

33

One difference is that the first option hides the intent by expressing the join condition in the where clause.

The second option, where the join condition is written out is more clear for the user reading the query. It shows the exact intent of the query.

As far as performance or any other difference, there shouldn't be any. Both queries should return the exact same result and perform the same under most RDBMS.

Icarus
  • 63,293
  • 14
  • 100
  • 115
4

The inner join syntax was added to SQL sometime in the 1990s. It's possible, but unlikely, that the optimizer can do better with it than with the old syntax that used the where clause for the join condition.

They should both be highly portable as things are now.

The inner join syntax is preferable because it is easier on the reader, as others have already remarked.

Walter Mitty
  • 18,205
  • 2
  • 28
  • 58
1

Both are standard SQL. Different DB systems may optimize them differently, but because they are so simple, I would be a little surprised if they do. But that is the nature of SQL: it is declarative, which gives the implementation a great deal of leeway in how to execute your query. There is no guarantee that these perform the same, or if they are different, which is faster.

Ned Batchelder
  • 364,293
  • 75
  • 561
  • 662
0

They are exactly the same in SQL server. There is no performance difference.

Bishnu Paudel
  • 2,083
  • 1
  • 21
  • 39