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

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

Related

Difference between INNER JOIN and , COMMA [duplicate]

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

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 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.

what is the advantage of inner join tables [duplicate]

This question already has answers here:
INNER JOIN ON vs WHERE clause
(12 answers)
Closed 9 years ago.
imagine I have 2 simple tables
users (id,username,password)
shopping(user_id,product_id)
and I use inner join to find each username buys which product :
select username,product_id
from shopping
inner join users
on users.id=shopping.user_id
but I can write a more simple query without using inner join and it works
select username,product_id
from shopping,users
where shopping.user_id=users.id
and result is the same
I wonder to know what's the advantage of using inner join !!
Inner Join is Used to Extract the Data's from one or more tables, that's why we are going for inner join instead of Where condition
SQL statements are synonymous, though specifying the INNER JOIN is the preferred method and follows ISO format. I prefer it as well because it limits the plumbing of joining the tables from your where clause and makes the goal of your query clearer.

Whether to use JOIN or not? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
INNER JOIN versus WHERE clause — any difference?
SQL JOIN: is there a difference between USING, ON or WHERE?
For example, I have this SQL statement:
SELECT *
FROM orders, inventory
WHERE orders.product = inventory.product
or
SELECT *
FROM orders
JOIN inventory
ON orders.product = inventory.product
What is the difference between these two?
They do exactly the same thing, but I'd recommend the second approach for readability and maintainability.
Using JOIN allows you to separate the conditions that define relationships between tables from conditions which are filters on the result set.
Using JOIN makes it easier to see if you are missing a join condition.
Using JOIN allows you to easily choose between INNER or OUTER JOIN. The comma syntax is equivalent to INNER JOIN (though some databases do have an extension to allow an outer join when using the first approach).
The most important is to be consistent about which you use. The comma syntax has different precedence from the JOIN keyword which can lead to confusing errors if you try to mix the two syntaxes in the same query. Because of point 3, it is easier to be consistent if you always use JOIN.
Inner join is ansi syntax, should be the preferred method.
Imagine how ugly this solution could get if you were to use the , with say many tables?
SELECT * FROM orders, inventory, products, logistics, accounting, materials, ...
Be kind to your future developers and anyone else looking at or maintaining this code use the JOIN syntax.
The comma (,) is equivalent to an CROSS JOIN. Using an explicit CROSS JOIN is more intuitive and recommended, as it can easily be changed to a LEFT JOIN, RIGHT JOIN, etc. Using CROSS JOIN is also ANSI-compliant.
They are functionally equivalent. The second one is 'newer'.