SubQuery

  • Comments posted to this topic are about the item SubQuery

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • Got it wrong.

    I thought that there would be an error because the StudentId column has the alias "StudentNumber" inside the subquery and in line 25 it's being declared as StudentId again.

    Interesting behaviour. Learned something new. 🙂

    Thank you for the question.

    Best regards,

    Best regards,

    Andre Guerreiro Neto

    Database Analyst
    http://www.softplan.com.br
    MCITPx1/MCTSx2/MCSE/MCSA

  • Happy to report that I am first to get this right.

    I don't enjoy this sort of question though - I am a human, not a T-SQL parser.

    The question could have made the same point, with the same learning value, much more simply.

  • SQL Kiwi (9/17/2011)


    Happy to report that I am first to get this right.

    I don't enjoy this sort of question though - I am a human, not a T-SQL parser.

    The question could have made the same point, with the same learning value, much more simply.

    It was due to that human nature (it is very easy for people to make a mistake in column aliasing as shown here) I wanted to demonstrate the question like this. As you said though, I could have given a much simpler example. This just happened to be one that I was working on as an answer to a forum question at the time of submission.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • SQLRNNR (9/17/2011)


    ...This just happened to be one that I was working on as an answer to a forum question at the time of submission.

    I see. Thanks for the explanation.

  • Indeed, it's an interesting thing to learn. Thanks.

  • Sudhir Dwivedi (9/18/2011)


    Indeed, it's an interesting thing to learn. Thanks.

    You're welcome.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • Nice question.

    I chose the third (wrong) answer because I didn't notice the DATE data type and thought it was DATETIME 🙂

  • JOIN (SELECT StudentId as StudentNumber, max(RequestNbr) as RequestNb

    FROM Request

    ...

    GROUP BY StudentId) as Latest (StudentId, RequestNbr)

    ON Request.StudentId = Latest.StudentId

    AND Request.RequestNbr = Latest.RequestNbr

    Just to clearify. The whole point was to point out that the bold parts dont match and that SQL instead is using the italic names in the join?

    If above is true then read on... otherwise ignore:

    I got the answer right for all the wrong reasons. I simply didnt see the change in the names. And it took one heck off a time to see the change in the names. When i first read the question i was so sure it would be something odd about the DATE datatype (since one answer had timeportion in it) or something with the MAX in the subquery. So i focused on that but couldnt find anything odd about it. So that left me with only one answer. Which was the right answer.

    PS Im not being sarcastic or anything. I for one learned something... if my assumption is correct. Its just that in this case i feel like the point was drowned in code that wasnt relevant. Though atleast it made me think ALOT 😀

    /T

  • DOH! Right answer, for the wrong reason.

    I completely missed the aliases and selected the correct answer on the DATE type.

    So I learnt something and won a checky point.

    Making this my favorite QotD so far this week 🙂

  • This was removed by the editor as SPAM

  • Nice question ... interesting to learn something new too.

  • Got it right, even though the correct answer isn't listed. But I guessed rightly that the author assumed we all use US date formats 😉

  • Tough question with the amount of T-SQL to review, but I did get it correct. I think it was more luck than anything.

    http://brittcluff.blogspot.com/

  • Thanks. Got it right - but almost went for the first instance of the name change. Good thing I kept "parsing". Thanks for the lesson!

    [font="Verdana"]Please don't go. The drones need you. They look up to you.[/font]
    Connect to me on LinkedIn

Viewing 15 posts - 1 through 15 (of 34 total)

You must be logged in to reply to this topic. Login to reply