0

What are the differences between these two SQL queries?

Query #1:

select mytab.name, mytab.age, films.title, films.author 
from films, mytab 
where films.id = mytab.id;

Query #2:

select mytab.name, mytab.age, films.title, films.author 
from films inner join mytab 
on films.id = mytab.id;

First is a normal SQL query using 'where' statement. The second is using inner join. The result of both queries is exactly the same.

films -> id, title author
mytab -> id, name, age

It`s the poorest example as is possible.

Here is analogical example : http://www.w3schools.com/sql/sql_join_inner.asp

marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
user1519221
  • 601
  • 4
  • 13
  • 21

2 Answers2

2

They are logically equivalent, and will produce the same results.

The first uses older join syntax.

Second uses the ANSI-92 join syntax, and is the preferred style.

Mitch Wheat
  • 288,400
  • 42
  • 452
  • 532
2

Both Queries will yield same results but the only difference is in syntax,

1st query uses old syntax for join where you describe the relation in WHERE clause .

2nd Query uses newer ANSI syntax, where relation between tables are defined in ON clause.

Second syntax is preferred though.

Read Here for more information.

Community
  • 1
  • 1
M.Ali
  • 65,124
  • 12
  • 92
  • 119