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

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.

Related

How do these two queries return the same result but use different joins? (Implicit vs. Explicit Query) [duplicate]

This question already has answers here:
Inner join vs Where
(19 answers)
Closed 2 years ago.
I have 2 tables: Order and Customer. Order has a foreign key from Customer:
I can join them in 2 different ways:
First way
Select *
from [Order]
join Customer
on [Order].Customer_id = Customer.id;
Second way
Select *
from [Order],Customer
where [Order].Customer_id = Customer.id;
The 2 queries return the same result set which leads me to my related questions:
Which query is the better of the two?
Is there a difference between them involving time execution?
Why is it that when I search join examples all of them are using the first way?
I learned the second type of query in college - is it wrong to use?
The difference occurs if you are using LEFT OUTER JOIN or RIGHT OUTER JOIN. filtration location matters here because criteria specified in the ON clause is applied before the JOIN is made. Criteria against an OUTER JOINed table provided in the WHERE clause is applied after the JOIN is made. This can produce very different result sets.
In comparison, it doesn't matter for INNER JOINs if the criteria is provided in the ON or WHERE clauses, the result will be the same.

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.

best practice: Oracle SQL Joins [duplicate]

This question already has answers here:
Condition within JOIN or WHERE
(10 answers)
Closed 9 years ago.
which example below is best practice for inner joins? the examples below are
pretty simple but, what if there are multiple tables involved?
which approach would you choose?
example queries:
simple
SELECT suppliers.supplier_id, suppliers.supplier_name, orders.order_date
FROM suppliers, orders
WHERE suppliers.supplier_id = orders.supplier_id;
using keyword INNER JOIN
SELECT suppliers.supplier_id, suppliers.supplier_name, orders.order_date
FROM suppliers
INNER JOIN orders
ON suppliers.supplier_id = orders.supplier_id;
Since 1992 ANSI recommends the JOIN notation, and regarding to readability this is what I would recommend using.
Everything has been said on this topic, but I will just remind that from a logical point of view it makes much more sense to separate the join conditions from the value filters for 2 reasons:
that's not the same thing at all
Oracle internally (and mysql probably too, even though I don't really know) first calculates intermediate recordsets and THEN, afterwards, applies the WHERE filters.
I'd recommend explicitly stating JOIN type and using ON clause.
But you need to use it correctly. In your example you forgot to include FROM clause and suppliers table.
SELECT suppliers.supplier_id,
suppliers.supplier_name,
orders.order_date
FROM suppliers s INNER JOIN
orders o ON s.supplier_id = o.supplier_id;
In terms of functionalities both WHERE AND JOINS are same..

Difference between these joins [duplicate]

This question already has answers here:
Inner join vs Where
(19 answers)
Closed 8 years ago.
Is there any difference between
SELECT *
FROM TABLE_A a
JOIN TABLE_B b
ON a.propertyA = b.propertyA
And the query
SELECT * from TABLE_A a, TABLE_B b where a.propertyA=b.propertyA.
INNER JOIN is ANSI (SQL-92) syntax which you use on the first one. It is generally considered more readable, especially when you join lots of tables.
The WHERE syntax (SQL-89) is more relational model oriented. A result of two tables JOIN'ed is a cartesian product of the tables to which a filter is applied which selects only those rows with joining columns matching.
It's easier to see this with the WHERE syntax.
I'd rather go on the ANSI type join because if you some how omit the ON clause, an error is generated whereas the old type of join if you omit the condition on where clause will not produce an error message and thus it will generate cartesian product.
The two examples are the same. Both perform an INNER JOIN operation (even if it's just JOIN in the 2nd example) which basically returns all rows that contain matching results in relation to the ON clause.
My guess is that the JOIN and INNER JOIN operations are just a bit faster since they're designed for that specific purpose while SELECT statements can be modified around to do much more.
The "join" version has been around about 20 years and is preferred because it clearly identifies predicates used for the join as opposed to those used for filtering results.
It also allow outer joins if used with left join (where you still get table_a's row if there isn't a matching row in table_b).
The "comma" version doesn't allow outer joins (you won't get table_a's row if there isn't a matching row in table_b)