Why Does The Alias Precede The Table Name?

Hi all,

I’m working on tightening up my Ecto skills and I wanted to post a question just to see if someone could give me a '“why” on a particular thing. I find that I have an easier time remembering things if I know the logic behind the way something is constructed.

I’m curious why the from clause in an Ecto query puts the alias first and then the table name. In SQL it’s the other way round:

Table t

vs.

from t in “table”

I’m sure there’s an excellent reason for this–likely something to do with the macros underlying Elixir but I just felt like indulging my curiosity a bit and asking this here.

Edit: I just realized I got my terminology backwards. Alias precedes table name

It is my understanding that Ecto is inspired by LINQ, a SQL query builder API from the Microsoft .NET world.

Here are some example LINQ queries (notice that the syntax is basically identical to Ecto):

var numQuery = from num in numbers
               where (num % 2) == 0
               select num;
IEnumerable<MyObject> results = from c in SomeCollection
                                where c.SomeProperty < 10
                                select new {c.SomeProperty, c.OtherProperty};

Here are some links that give some more information (they are also the source of the LINQ syntax examples posted above):

Thanks for the answer. Of course that brings the question to my mind–why doesn’t LINQ do it in the order that it occurs in SQL? :grinning_face: