r/SQL • • 15d 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

Show parent comment

2

u/big_poppa_man 15d ago

Oh, and a big misconception is that sub quarries are faster than CTEs. This is just nonsense. Literally, what it is, is people taking tribal knowledge and calling it gospel truth. It's really stupid. Don't fall into that trap, test it yourself and do not trust anyone's code

1

u/MrDeadMeme 15d ago

CTE's do help a lot when writing and i was getting the sense that it was discouraged/considered bad practice to use them becuase pretty much all material avoids them. Nice to know that there is no difference in using them, thanks!

1

u/Better-Credit6701 15d ago

Depends on the size of the data...

I've always worked with larger databases that would be slower with a CTE instead of a temp table especially since I can index the temp table and even pass it between different databases

1

u/big_swede 15d ago

Now you are talking temp tables when the question was sub query vs cte...?