Precedence

  • Comments posted to this topic are about the item Precedence

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • I got the question correct, but I answered it on the basis that the two where clauses were different.

    Where ID = 20 OR modelID = 20 --- NOTE the use of the ID column in one and modelID in the other

    and

    Where modelID = 20 OR modelID = 20 -- NOTE modelID in both clauses

    apart from that, perhaps the question should ask

    do the two statements return the same rows rather than do the select statements return the same number of rows.

    do get me think about the use of parentheses though.

    cheers

    Martin.

  • Good question but I thought the answer sounds evident. Many people would choose 'NO' as the answer because the question sounds like that 🙂

    M&M

  • The two WHERE clauses were different, so the correct answer ought to be "depends on the data"... 😀

  • I think it is fairly apparent that the author made a typo in the first select statement, and meant to have ModelID rather than just ID.

    Never the less, I answered NO and was ready to use that "error" in my argument had I got it wrong LOL!! 😛

    _____________________________________________________________________
    [font="Comic Sans MS"]"The difficult tasks we do immediately, the impossible takes a little longer"[/font]

  • The answer must be "it depends", since we know nothing at all about the data. At the most basic, if the table is empty then the two queries must return the same number of rows!

    I picked the most likely answer and got it right, as regardless of the operator precedence the two queries are looking at different columns.

  • Actually the default answer is the only right answer: It depends.

    You can't answer the question without knowing the data it is running on.

  • paul.knibbs (7/25/2011)


    The two WHERE clauses were different, so the correct answer ought to be "depends on the data"... 😀

    Exactly what I was thinking. I knew the difference in the WHERE clause but if the table didn't have any data in it, they would both return zero records which could make that a yes. Therefore, it should be "depends" as the correct answer.

    I did get this right though. I had to guess what the QOTD author was trying to test me on.

  • Having criticised so many questions for their errors, I would like to say that this is a really useful question, and raises so many issues of good query design.

    To whomsoever wrote and submitted it: Congratulations!

    Ken

    You never know: reading my book: "All about your computer" might just tell you something you never knew!
    lulu.com/kaspencer

  • Correct Ans must be it depends on data. Also it does return same number of rows for given database. (zero)

  • Good question, nice to confirm that T-SQL agrees with maths fundamentals.

    I really can't see the need to nitpick here. We know that "ID" was really "ModelID" and that there are circumstances where the records returned MIGHT be the same. That's not what the question was about though.

    _____________________________________________________________________
    MCSA SQL Server 2012

  • Richard Warr (7/25/2011)


    We know that "ID" was really "ModelID"

    No we don't. The query refers to both columns so the rtable presumably contains both. It's entirely possible that the question was intended to see whether we noticed the different columns used in the queries - especially given another similar "typo/non-typo" question last week.

    Richard Warr (7/25/2011)


    there are circumstances where the records returned MIGHT be the same.

    Exactly. Hence "it depends".

    Richard Warr (7/25/2011)


    That's not what the question was about though.

    But we didn't know that before we answered 😀

  • Toreador (7/25/2011)


    Richard Warr (7/25/2011)


    We know that "ID" was really "ModelID"

    Really. do we really.

    We can only answer based on the question.

    It's just a question. Not a test of your psychic ability 🙂

  • martin catherall (7/25/2011)


    It's just a question. Not a test of your psychic ability 🙂

    True, although common sense can often save despair and heartache.

    _____________________________________________________________________
    MCSA SQL Server 2012

  • 1) "It depends".

    2) "No", probably.

    3) ModelID was "probably" a typo.

    Both the actual table structure and the data contents were unknown. I'm fairly sure I could provide schemas and data sets, one that would render either a Yes and another that would give a No answer, to the queries as written.

    Mike Hinds Lead Database Administrator1st Source BankMCP, MCTS

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

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