0

Shortening SQL syntax

I came across this piece of code while learning about Joining Tables in SQL. Original code: SELECT customers.ID, customers.Name, orders.Name, orders.Amount FROM customers, orders WHERE customers.ID=orders.Customer_ID ORDER BY customers.ID; Why can't we just write as: SELECT customers.ID, customers.Name, orders.Name, orders.Amount WHERE customers.ID=orders.Customer_ID ORDER BY customers.ID; removing the 'FROM' part, because table names are specified in 'SELECT' part anyway? Wouldn't the code be shorter this way if SQL syntax allowed to do so?

26th Jun 2022, 8:21 PM
Solo
3 Answers
+ 3
I guess the designers did not think of that. OTOH, I think you would same more typing by including the FROM statement and using its alias feature - the AS phrase. SELECT C.ID, C.Name, O.Name, O.Amount FROM customers AS C, orders AS O WHERE C.ID=O.Customer_ID ORDER BY C.ID
26th Jun 2022, 8:48 PM
Brian
Brian - avatar
+ 1
The FROM clause is necessary, because as you can see from Brian's example, a table alias (shorter identifier) can be used. How the server knows which actual tables are involved when the FROM clause was missing while table aliases are there? how to know what 'C' and 'O' represent?
26th Jun 2022, 11:58 PM
Ipang
0
In that case FROM becomes optional same as AS
27th Jun 2022, 8:46 AM
Solo