Results 1 to 2 of 2

Thread: union all

  1. #1
    Join Date
    Apr 2004
    Posts
    15

    Arrow Unanswered: union all

    SELECT TagName ,COUNT(Tagname) as Total FROM Table1
    UNION ALL
    SELECT TagName ,COUNT(Tagname) as Total FROM Table2
    UNION ALL
    SELECT TagName ,COUNT(Tagname) as Total FROM Table3
    UNION ALL
    SELECT TagName ,COUNT(Tagname) as Total FROM Table4
    GROUP BY TagName


    I want to combine some tables with 1 column for Total, but the code above can't work.any suggestion?thanks

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    SELECT TagName ,COUNT(Tagname) as Total FROM Table1
    GROUP BY TagName
    UNION ALL
    SELECT TagName ,COUNT(Tagname) as Total FROM Table2
    GROUP BY TagName
    UNION ALL
    SELECT TagName ,COUNT(Tagname) as Total FROM Table3
    GROUP BY TagName
    UNION ALL
    SELECT TagName ,COUNT(Tagname) as Total FROM Table4
    GROUP BY TagName
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •