I’ve been looking at some code I find pretty difficult to follow lately. Lots of reasons, not least of which is my inexperience. But I think there are other reasons, too.
In the process of remembering & unlearning Clipper syntax and replacing it with sql, I ran across this demo of aliases on the W3Schools site.
Assume we have a table called “Persons” and another table called “Product_Orders”. We will give the table aliases of “p” and “po” respectively.
Now we want to list all the orders that “Ola Hansen” is responsible for.
We use the following SELECT statement:
SELECT po.OrderID, p.LastName, p.FirstName FROM Persons AS p, Product_Orders AS po WHERE p.LastName='Hansen' AND p.FirstName='Ola'
The same SELECT statement without aliases:
SELECT Product_Orders.OrderID, Persons.LastName, Persons.FirstName FROM Persons, Product_Orders WHERE Persons.LastName='Hansen' AND Persons.FirstName='Ola'
As you’ll see from the two SELECT statements above; aliases can make queries easier to both write and to read.
This surprised me. Do y’all find the second easier to read?