|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 5:22 PM
Points: 1,117,
Visits: 1,145
|
|
Thanks for the question!
-Dan
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 4:53 PM
Points: 7,182,
Visits: 7,281
|
|
Good question.
I got it wrong. Q1 is obviously wroing, and I immediately concluded it was all about "order by" and just skim the rest for "order by" related errors - so missed the obvious problem with 4. Another confirmation that one should read code carefully, not skim it carelessly.
Tom Is minic a gheibheann béal oscailte dorn dúnta. Is minig a cheapas beul fosgailte dòrn dùinte.
http://es.linkedin.com/in/tomthomsonsoftware
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 4:53 PM
Points: 7,182,
Visits: 7,281
|
|
But of course one could say that the query processing ought to notice that there is no ambiguity in number 4, because any possible ambiguity is eliminated by the ON clause of the join. Would such ambiguity elimination be a good thing or a bad thing? I'm in two minds about it.
Tom Is minic a gheibheann béal oscailte dorn dúnta. Is minig a cheapas beul fosgailte dòrn dùinte.
http://es.linkedin.com/in/tomthomsonsoftware
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, January 24, 2013 9:59 PM
Points: 1,354,
Visits: 1,299
|
|
Tom.Thomson (9/7/2011) But of course one could say that the query processing ought to notice that there is no ambiguity in number 4, because any possible ambiguity is eliminated by the ON clause of the join. Would such ambiguity elimination be a good thing or a bad thing? I'm in two minds about it.Because the two values are equal, I agree that it's not technical ambiguity; however, you can use nonequalities in the joins too like:
ON Column1 > Column2
Shouldn't happen often but the complexities in the query optimizer would be too difficult for Microsoft to handle 
And to make it clear, it was due to the ORDER BY clause so the subject of the QOTD was still okay. If you were to remove the ORDER BY clauses, all 4 queries would run properly. Query 1 and 4 fail because of the invalid ORDER BY clauses -- not because of any other reason.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 6:08 AM
Points: 1,216,
Visits: 298
|
|
| Thanks for the nice questions!!
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, May 21, 2013 8:56 AM
Points: 2,
Visits: 34
|
|
| I agree.. Never would have put the Order by in the sub because I don't see the reason too. So I would have never learn it would fail until now
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Wednesday, October 24, 2012 8:17 PM
Points: 1,588,
Visits: 247
|
|
Really had to think through this one. Thanks for a tough question of the day.
http://brittcluff.blogspot.com/
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, November 01, 2011 1:53 AM
Points: 13,
Visits: 14
|
|
| 3rd will also fail since ambiguous column with order by.
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Thursday, November 22, 2012 11:19 PM
Points: 410,
Visits: 112
|
|
| Query 3 would fail because both tables contain employee id column but, alias name of employee id have not been used in order by clause. Please check for the Query 3 and revert back.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, January 24, 2013 9:59 PM
Points: 1,354,
Visits: 1,299
|
|
Nandhini Ramanujam (5/31/2012) Query 3 would fail because both tables contain employee id column but, alias name of employee id have not been used in order by clause. Please check for the Query 3 and revert back.
Query 3 does not fail. if there is more than one EmployeeID column, the ORDER BY clause uses the one that is in the select statement. There is only one in the select statement so the query executes just fine.
|
|
|
|