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
  • 732,580
  • 175
  • 1,330
  • 1,459
user1519221
  • 631
  • 5
  • 13
  • 24

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
  • 295,962
  • 43
  • 465
  • 541
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
  • 67,945
  • 13
  • 101
  • 127