by ainar-g · 7y ago · 0 comments
OTOH FROM first is better for tooling.
Really, there's no really good reason for a mandatory order of clauses in an SQL statement.
The thing I always imagine is a bunch of people in the 1970ies sitting around designing this stuff, and reading it out loud in a Captain Kirk voice
"Computer, SELECT course WHERE Klingons IS zero!"
For some reason that made sense to me.
WITH
employee AS (SELECT * FROM EMPLOYEES),
department AS (SELECT * FROM DEPARTMENTS)
SELECT employee.name, department.name
FROM employee
INNER JOIN department ON employee.department_id = department.department_idFrom a source code structure perspective "SELECT foo ...;" sort of works like a function header: "function foo() { ... };"
- 1. create a bunch of constructs to work towards that goal -
- 2. work happens -
- 3. finally get my output and have what i want -
1. "SELECT *" because habits
2. Start writing the FROM/JOINs and table aliases
3. Go back and refine the SELECT to tableAlias.ColumnName
4. (OPTIONAL) Aggregates
5. Forget the WHERE clause and burn the optimizer's cached query plans to the ground! (j/k, add WHERE or just throw a TOP 500 into the SELECT)