Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2005
    Posts
    16

    Unanswered: Nested Query Troubles...

    Hi All,

    Can anybody please tell me if a query such as this (Valid in MS Access)
    can work in SQL Server:

    Code:
    SELECT Description, Sum(Total) FROM (
        SELECT Description, Total FROM Table_A
            UNION ALL
        SELECT Description, Total FROM Table_B
          UNION ALL
        SELECT Description, Total FROM Table_C
    )
    GROUP BY Description
    The group of unions work by themselves, but when I try to nest an outer query to do some a Summation(), I have syntax errors.

    Any insight would be greatly appreciated. Thank you.

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    You must supply an alias for your subquery:
    Code:
    SELECT	Description,
    	Sum(Total)
    FROM	(SELECT	Description,
    		Total
    	FROM	Table_A
    	UNION ALL
    	SELECT	Description,
    		Total
    	FROM	Table_B
    	UNION ALL
    	SELECT	Description,
    		Total
    	FROM	Table_C) AS SUBQUERY
    GROUP BY Description
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  3. #3
    Join Date
    Apr 2005
    Posts
    16

    Smile

    Thanks BlindMan, u da man.


Posting Permissions

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