UNION ALL is hanging the server and is very slow.

  • D'oh... This is what I get for reading forum posts when my caffeine level is low. I completely missed the part where it's doing multiple hits on a view. In cases like these I'd have used the sum(case...) as well. Inserting into temp tables can be very efficient, but not when views are involved.

  • Temp tables are used to divided and conquer. That means you have a huge a$$ query or huge a. table and you have slow performance. Then building the same query in 2 steps can be very beneficial. But you always have to account for the penalty to insert and then reselect.

    This was a clear cut case of select sum...

  • a

  • Ninja's code has the additional benefit that it will give correct results. If there are any columns in the invoice table's PK that are not in the SELECT clause, there could be two or more identical rows. UNION without UNION ALL will, as has been pointed out, remove those rows. Probably not what was intended.

  • sunnymalhotra (4/11/2011)


    a

    SELECT 'a' --marble

    FROM AAA --Stupid car...

    WHERE EH! = A

    GROUP BY Eeeehhhhh... --Fonzy anyone?

    HAVING COUNT( '''eh') >= CanadaOnOneDay

    ORDER BY [Aaaaaaaaaahhhhhh... Calgon Take Me Away!]


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

Viewing 5 posts - 16 through 19 (of 19 total)

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