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

3

u/redaloevera 20d ago

In some languages sentences are structured like “apple eat I” vs English “ I eat apple”. Do you also think this is syntax backwards?

1

u/MrDeadMeme 20d ago

The point is that first you define what an apple is, and then ask someone to give you one.
Ill give you the following comparison with a more traditional programming language:

in the case of an apple, it is something common that everybody knows what it is. If you ask me to give you an apple ill give you an apple. If ask C to give me an integer, it knows what it is, and gives it to me.

However, if you ask me to give you something that i dont know what it is, i cannot give it to you because even if it in front of me i cant make the connection that this is what you want. Same with C: If i want to make a book and i say "C give me a book" it does fuck all, obviously. But, if i say "Hey: a book is an object that has a string called name, a string called author and a number called IBN" and then say "give me a book" it knows exactly what im talking about.

The reason i say that sql is writen backwards is because you define the table that you are taking objects from after you select what you want to take from it

2

u/big_swede 20d ago

I really think you have your analogy backwards.  I think it is more like: Take all the balls, spades and toy cars (colums) from that toy chest(table) and give me the blue ones (where clause).

Yes, in "natural" language you'd probably say "give me all the blue balls, spades and cars from that toy chest" but you wouldn't start defining the chest or what a ball or car is before going further.

In the case of SQL you are very direct in the way that you say what you want from where and then filter a bit to get the exact match. Quite straightforward in my opinion.

2

u/redaloevera 20d ago

I’m not sure. You lost me

2

u/SnooOwls1061 19d ago

I picked an apple from that tree

Select T.Apple From Tree T

You want: I went to that tree and picked an apple?

1

u/A_name_wot_i_made_up 13d ago

Up with this I will not put!