I'm new to SQL and am having trouble understanding why there's a FROM
keyword in a JOIN
statement if I use dot notation to select the tables.columns
that I want. Does it matter which table I choose out of the two? I didn't see any explanation for this in w3schools definition on which table is the FROM
table. In the example below, how do I know which table to choose for the FROM
? Since I essentially already selected which table.column
to select, can it be either?
For example:
SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
INNER JOIN Orders
ON Customers.CustomerID=Orders.CustomerID
ORDER BY Customers.CustomerName;
FROM
table: what you're actually selecting "from" is the result from the join operation, not one table or the other. What the SQL is specifying is "join" operation on two tables "Customers JOIN Orders ON ...
". The query is selecting "from" the result of the join operation. (The order of the expressions in the equality comparison don't matter either.a.col = b.col
is equivalent to specifyingb.col = a.col
; a property of the equality comparison operator.) It's best practice to qualify all column references in the query (as is shown in your example.) – spencer7593 Oct 3 '14 at 19:18