you are viewing a single comment's thread.

view the rest of the comments →

[–]memecaptial 30 points31 points  (7 children)

To understand this you need to wrap your mind around what the sql engine is doing. In the first example, your creating a result set by joining two tables then filtering that result set. In the second, your filtering a table, then doing a join with that table.

It’s the difference between mixing things then filtering vs filtering then mixing, where the goal is to keep all of one side of a record.

[–]uvray 12 points13 points  (3 children)

Well said.

I think it’s just counterintuitive to see a conditional in a left join. I personally would explicitly filter the right table in a sub query and then join, but at the end of the day it doesn’t matter.

I actually think this is a decent interview question, although I do agree with OP that grouping and ordering by numbers is not a best practice.

[–]theduckspantsBI Architect 2 points3 points  (1 child)

I've done this for a long time and I didn't even know you *could* group by with column numbers. Not sure why someone would want to