r/SQL • • 19d ago

Discussion Why do we keep writing sql backwards?

It is a common consensus that sql is kind of written backwards than one would expect, instead of first defining the place you want to get somehting from and then what it is you want, like literally any other language out there, you first select the content and then define where you want it to be taken from

This leads to increadibly akward syntax when writing something more complex than "select x from y where z" and is literally opposite to the actual process of the machine.

This is all because some dumbass, excuse my language, in the 70's decided it should follow english grammar for some reason, and in doing so he made the most clunky writing system ever.

Now this at the time may not have been that bad, but from a few searches and posts here i saw that most people agree that this is a clunky, akward and unpleasant way of typing. So, why not switch it around? Why not change the standard to something more usable?

This is kind of a rant because i have been learning sql for collage and the syntax has been INCREADIBLY frustrating

0 Upvotes

30 comments sorted by

View all comments

1

u/Significant_Tune9219 19d ago

The order you write it in is closer to how it gets evaluated than it looks if you read it as FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY, and that order is also why you can't use a SELECT alias in WHERE but can in ORDER BY. A habit that helps when learning is to actually write the FROM and joins first, then the WHERE, and fill in the SELECT list last. If you want to try the other way round, several engines now accept a FROM-first syntax with pipe operators, so the idea isn't crazy, it's just that the standard is fifty years of compatibility.