Union All

  • Hi,

    table A which has 4 records

    union all

    Table B -has 4 records --getting result set using 3 tables

    union all

    table c - has 4 records

    ..

    when i use union all I'm getting 12 records altogether in a result set..

    My question is i want to see the sum of all records so that i will get only 1 record in the result set.

  • SELECT SUM(SomeColumn) FROM (

    SELECT SomeColumn FROM TableA

    UNION ALL

    SELECT SomeColumn FROM TableB

    UNION ALL

    SELECT SomeColumn FROM TableC) sub

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • The columns in the table a ,b ,c are already using aggregate functions like max(duration) ,min(perf),avg(proc)

  • It worked .

    Thanks Gil.

Viewing 4 posts - 1 through 3 (of 3 total)

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