Order of execution

Screen Link: Computing SQL Summary Statistics | Dataquest
In the previous links, it was given that the execution priority was - FROM, WHERE, SELECT, ORDER_BY, LIMIT. However, when doing the above screen question, I faced that we did naming of the columns in SELECT column and used in WHERE column. However, the WHERE column will come before in the order of priority.

Can you please share the code you are using for this screen so that we can see what you mean? FYI - we do not need to use a WHERE clause to pass this screen.

That said, I believe the reason for the confusion you’re describing is due to how sqlite differs from other flavours of SQL. Most do not allow an alias in the WHERE clause but sqlite does. Check out this StackOverflow post for more on the subject.

Hi mike,

Please read the following link -
Computing SQL Summary Statistics | Dataquest

If we are doing alias in SELECT and using the alias in WHERE, How is this possible that we are using the alias first then defining it. (The link showed that Where function’s order will be followed by Select. So technically we are using alias before we are even defining it)

Hi @keswani06 , have you checked out the link I provided to the SO post? There you can read how sqlite (the flavour of SQL used on the DataQuest platform) is different than “regular” SQL and has a few quirks like what you are experiencing.

Also, check out this similar post in the community which says the same thing as well as contains links to other resources.

@keswani06 As Mike says, SQLite works a little different. It is flexible in allowing aliases defined in the SELECT clause to be used in WHERE. This isn’t portable to many other SQL flavors (as Mike also said), however.

So while it works in SQLite, from a learning point of view we discourage it. You can very well end up working in another database, say, Postgres, and such things not working there. So we focus on “pure” SQL.

1 Like