Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between inner join and where in select join SQL statement [duplicate]

Tags:

sql

join

select

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.

like image 947
爱国者 Avatar asked Jul 18 '12 03:07

爱国者


People also ask

What is the difference between WHERE and inner join?

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

Does inner join keep duplicates?

The answer is yes, if there are any. If there are duplicate keys in the tables being joined.

Why inner join gives duplicate records?

Using an Incomplete ON Condition Unwanted rows in the result set may come from incomplete ON conditions. In some cases, you need to join tables by multiple columns. In these situations, if you use only one pair of columns, it results in duplicate rows.

Which is faster inner join or WHERE clause?

The subquery can be placed in the following SQL clauses they are WHERE clause, HAVING clause, FROM clause. Advantages Of Joins: The advantage of a join includes that it executes faster. The retrieval time of the query using joins almost always will be faster than that of a subquery.


1 Answers

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.

like image 130
Icarus Avatar answered Sep 20 '22 14:09

Icarus