Difference between INNER JOIN and , COMMA [duplicate] - sql

This question already has answers here:
Explicit vs implicit SQL joins
(12 answers)
Closed 5 years ago.
I get the same result in both queries below and same execution plan, any difference? or it is just how I prefer to write my query?
SELECT PS.StepID,PR.ProgramID FROM ProgramSteps PS, Programs PR
WHERE PS.ProgramID = PR.ProgramID
SELECT PS.StepID,PR.ProgramID FROM ProgramSteps PS
INNER JOIN Programs PR ON PS.ProgramID = PR.ProgramID

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.
And as #Tim Biegeleisen says in the comments:
the comma version is deprecated as of the ANSI-92 SQL standard

Related

What is the difference between JOIN and SELECT? [duplicate]

This question already has answers here:
INNER JOIN ON vs WHERE clause
(12 answers)
Closed 9 years ago.
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.
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.
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.
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.
They are exactly the same in SQL server. There is no performance difference.

Are these two select sql statements equal? "join...on" vs. "where" [duplicate]

This question already has answers here:
INNER JOIN ON vs WHERE clause
(12 answers)
Closed 5 years ago.
Are the following two select SQL statements exactly equal? I usually use the join keyword, but I found that the sqlite author uses the second form in some of his document pages on sqlite.org.
The "inner join...on" form
SELECT * FROM Order INNER JOIN OrderItem ON Order.Id = OrderItem.ParentId
The "where" form
SELECT * FROM Order, OrderItem WHERE Order.Id = OrderItem.ParentId
Update 1:
I found this question might be duplicated, it seems has something to do with the SQL89 and SQL92 standards, but it doesn't answer me the second form is an "INNER JOIN", "OUTER JOIN" or anything else.
Result will be the same but there are separate purpose of each syntax.
for more details check this inner join vs where
If you talk about specifically the query you mentioned then yes both will result the same but join and where clause don't give same results. join is used for joining two tables and where clause is further used to specify the data selection from those tables.

What are the differences between JOIN statement and one without it? [duplicate]

This question already has answers here:
Explicit vs implicit SQL joins
(12 answers)
Closed 6 years ago.
I am currently learning SQL. I am trying to create Views using Oracle SQL Developer. I came across the JOIN statement but I do not understand why do we need JOIN. According to W3School, the purpose of JOIN is to join multiple rows together. I can do that without the expression JOIN (refer to the following code blocks, both of them produce the same view/table). So what is the purpose of JOIN?
With INNER JOIN:
SELECT
Acc.Cust_Id,
Cus.Address,
Acc.Avail_Balance
FROM
Account Acc
INNER JOIN
Customer Cus
ON
Acc.Cust_Id = Cus.CUST_ID
Without INNER JOIN:
SELECT
Acc.Cust_Id,
Cus.Address,
Acc.Avail_Balance
FROM
Account Acc,
Customer Cus
WHERE
Acc.Cust_Id = Cus.CUST_ID
The two queries are the same, except the 1st one ANSI-92 SQL syntax and the and other is older SQL syntax which didn't incorporate the join clause. They should produce exactly the same internal query plan, although you may like to check.
check This link
ANSI vs. non-ANSI SQL JOIN syntax

What are the difference between these two SQL queries? [duplicate]

This question already has answers here:
Will ANSI JOIN vs. non-ANSI JOIN queries perform differently?
(7 answers)
Closed 8 years ago.
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
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.
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.

SQL 'WHERE' versus 'ON' (inner join) [duplicate]

This question already has answers here:
Inner join vs Where
(19 answers)
SQL JOIN - WHERE clause vs. ON clause
(22 answers)
INNER JOIN ON vs WHERE clause
(12 answers)
Closed 9 years ago.
When doing an SQL query,
is there any significant (or any at all) difference in performance between 'WHERE' and 'ON'?
I know there is a significant difference in the resulting set between the two for a LEFT or RIGHT JOIN.
What about an INNER JOIN?
Is there any drawback to using 'ON' for each of my selects rather than 'WHERE' at the end?
Performance wise, they should be the same. However, see this article for an opinion of an industry veteran regarding the readability and maintenace-friendliness.
While the old-style joins still work, you can't do an outer join anymore
Execution plans for both are identical. Many people prefer the use of ON though.