Using Max()

  • Comments posted to this topic are about the item Using Max()

    Developer, DBA, Pre-Sales consultant.

  • Very good question - got caught out with as well. Should have realized that with out the where clause that each max() is evaluated individually... nice to learn something at the end of the week.

    Hope this helps...

    Ford Fairlane
    Rock and Roll Detective

  • A good back to basics question. Thanks!

  • palotaiarpad (11/8/2013)


    A good back to basics question. Thanks!

    Indeed, sometimes the basics need to covered. Whilst really technical questions are great, the more commonly used functions are sometimes overlooked....

    Developer, DBA, Pre-Sales consultant.

  • Ford Fairlane (11/7/2013)


    Very good question - got caught out with as well. Should have realized that with out the where clause that each max() is evaluated individually... nice to learn something at the end of the week.

    This has very little to do with the absence of a WHERE clause. The aggregate functions are always individually evaluated within the set of rows on which the aggregate operates.


    Just because you're right doesn't mean everybody else is wrong.

  • Rune Bivrin (11/8/2013)


    Ford Fairlane (11/7/2013)


    Very good question - got caught out with as well. Should have realized that with out the where clause that each max() is evaluated individually... nice to learn something at the end of the week.

    This has very little to do with the absence of a WHERE clause. The aggregate functions are always individually evaluated within the set of rows on which the aggregate operates.

    You're right, it's more to do with an assumption that the MAX function "acts" like a WHERE clause, which is why people got the answer wrong.

    Developer, DBA, Pre-Sales consultant.

  • This was removed by the editor as SPAM

  • I couldn't believe!

    I never expected this kind of question!

    It is the same as:

    any number multiplied by 0 returns ZERO,

    so, you assume that any number added to zero should return ZERO!

    :w00t:

  • Good question!

    I found it easy even before my coffee :-), and I guess everybody have run this anytime

    SELECT MIN(ID), MAX(ID) FROM TABLE

    which is pretty the same.

  • Easy question for end the week...

  • I'm sorry, but what?

    I'm missing the point of this question. Why would anyone think it could be one of the other answers?

  • waxingsatirical (11/8/2013)


    I'm sorry, but what?

    I'm missing the point of this question. Why would anyone think it could be one of the other answers?

    I suggest you read some of the posts prior to yours. This may help you in your quandary 🙂

    _____________________________________________________________________
    MCSA SQL Server 2012

  • I kind of agree with waxingsatirical...it never occurred to me anyone would think this works otherwise, and I spent a good few minutes trying to figure out what unexpected behaviour of MAX() the question could be asking for! Eventually I just gave up and answered what I thought would happen, just to see what the answer was, and was somewhat surprised when that turned out to be correct. Guess I'm too used to QotDs looking for knowledge of odd bugs or weird behaviour!

  • Good question to end the week. Not everyone knows the basics, so a simple one every once it a while isn't a bad thing.

  • paul.knibbs (11/8/2013)


    I kind of agree with waxingsatirical...it never occurred to me anyone would think this works otherwise, and I spent a good few minutes trying to figure out what unexpected behaviour of MAX() the question could be asking for! Eventually I just gave up and answered what I thought would happen, just to see what the answer was, and was somewhat surprised when that turned out to be correct. Guess I'm too used to QotDs looking for knowledge of odd bugs or weird behaviour!

    Well, as of now 97 people (29%) have answered incorrectly. So there you go...

    ---------------
    Mel. 😎

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

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