I have two tables in database one is Orders
and another one is customers
Orders Table Contains : OrderID , CustomerID and OrderDate
Customers Table Contains: CustomerID , CustomerName , ContactName and country
Actually the "CustomerID" column in the "Orders" table refers to the
"CustomerID" in the "Customers" table. The relationship between the
two tables above is the "CustomerID" column.
Query with Join
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders
INNER JOIN Customers
ON Orders.CustomerID=Customers.CustomerID;
Simple Query
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders,Customers
WHERE Orders.CustomerID=Customers.CustomerID;
Result of Both Queries is : OrderID , CustomerName and OrderDate
On both the above query i get the same result . I want to know the difference between these queries and if we can do it via SIMPLE query why use JOIN?
Best Answer
There is no difference: your two examples are completely equivalent but using different versions of SQL syntax. The database engine will handle them in exactly the same way.
Your first example is using an explicit join and is the preferred syntax these days. It was introduced in the SQL-92 standard and is supported by pretty much every SQL-style query engine.
Your second example is usually referred to as an implicit join. It is an older syntax but still supported by most SQL based query engines and is still in the standard (so is considered to be correct even though the newer syntax is preferred). It quickly fell out of favour with the introduction and wide support of explicit joins as these are usually clearer and easier to read & maintain (though the older syntax could be said to have the advantage of being more concise).
See https://en.wikipedia.org/wiki/Join_(SQL) for further examples of this and other join types, including some engine specific variations.