INTERSECT 2

  • Comments posted to this topic are about the item INTERSECT 2

    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]

  • Thanks for the question.

    There is one thing not mentioned in the explanation, but very important to keep in mind: the INTERSECT statement and the SELECT #4 do not always return the same results. If both tables #A and #B contain NULL values, the INTERSECT statement will return a NULL value in the result set, while the SELECT #4 won't.

    This behavior is documented in Books Online (http://msdn.microsoft.com/en-us/library/ms188055.aspx)

    EXCEPT and INTERSECT (Transact-SQL)

    Remarks


    When you compare rows for determining distinct values, two NULL values are considered equal.

  • there is no GO after creation of table #B. In my opinion the select statements will fail with an error.

    I didn't try it out but that's what I suspect.

    Vera

  • Nice question, thanks. And thanks to vk-kirov for the remark.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Vera-428803 (6/19/2012)


    there is no GO after creation of table #B. In my opinion the select statements will fail with an error.

    I didn't try it out but that's what I suspect.

    Vera

    I think the statements will run just fine.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • All looked good to me - thanks for the question!

    Any ideas on the performance differences between the INTERSECT and INNER JOIN methods?

  • This was removed by the editor as SPAM

  • Richard Warr (6/19/2012)


    All looked good to me - thanks for the question!

    Any ideas on the performance differences between the INTERSECT and INNER JOIN methods?

    I suspect the explain plans and performance will be identical.

  • Great back-to-basics question and I got it wrong because I wasn't paying enough attention. Err...

    I think there is a copy and paste mistake in SELECT #2 and SELECT #3 as both are the same code. I guess you meant one LEFT JOIN with the DISTINCT and the other without it, right?

    BTW, thank you for the link with the article.

    Best regards,

    Andre Guerreiro Neto

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

  • I might overlook something, but aren't option 2 and 3 the same?

  • Mighty (6/19/2012)


    I might overlook something, but aren't option 2 and 3 the same?

    Nope, they are the same. The idea was probably that one of the two didn't have the DISTINCT clause.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Appreciate the question. Had to think for a minute, as I almost never use OUTER joins.

    A totally unrelated aside: Back from vacation. Missed the QotD. Didn't miss work.

    Spent 17 days in Greece. PLEASE consider a vacation there this year. The place is almost devoid of tourists, and for no good reason. In spite of their troubles, the Greeks were as gracious, warm, and hospitable as ever.

    End of totally unrelated comment.

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

  • it really helped that #2 and #3 are exactly the same, then i knew about the distinct so by process of elimination.... 1 pt.

  • no riots?

  • Thomas Abraham (6/19/2012)


    Appreciate the question. Had to think for a minute, as I almost never use OUTER joins.

    A totally unrelated aside: Back from vacation. Missed the QotD. Didn't miss work.

    Spent 17 days in Greece. PLEASE consider a vacation there this year. The place is almost devoid of tourists, and for no good reason. In spite of their troubles, the Greeks were as gracious, warm, and hospitable as ever.

    End of totally unrelated comment.

    no riots?

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

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