0

I would like to know which is the difference between a query with a join and a query with several tables at the FROM clause.

For example:

SELECT *
FROM table1 NATURAL JOIN table2.

or

SELECT *
FROM table1, table2
WHERE table1.field=table2.field.

Thank you so much.

user1966562
  • 73
  • 1
  • 4
  • 1
    One is an explicit join while the other is an implicit join - see [this question](http://stackoverflow.com/questions/44917/explicit-vs-implicit-sql-joins). –  Jun 22 '13 at 17:57

3 Answers3

1

NATURAL JOIN compares all columns of both tables and equals those who have the same name and the same type.

So basically, these two SQL statements will do the same operation if and only if the table1 and table2 have only one column with the same name and type, and that column is field.

darijan
  • 9,725
  • 25
  • 38
0

An SQL JOIN clause is used to combine rows from two or more tables, based on a common field between them.

The most common type of join is: SQL INNER JOIN (simple join). An SQL INNER JOIN return all rows from multiple tables where the join condition is met.

You can do also with WHERE but is to logical with JOIN. Use the WHERE for specific condition.

rpasianotto
  • 1,383
  • 1
  • 9
  • 22
0

Usually there is no difference whatsoever and database translates both into identical execution plan.

The two differences are:

  • join syntax allows you to do outer joins,
  • join syntax allows you to use "natural" and "using", and they in turn merge two input columns into one output column (so your first query will have one column less than the second one)
fdreger
  • 12,264
  • 1
  • 36
  • 42