SELECT MAX from select sum(...)+select sum(...)

I am having a lot of problems with the following structure. Please could anybody help me with this.

            SELECT
                MAX(intermediate.test)
            FROM               
              (
              
              SELECT SUM(table.field) FROM tabledfsd INNER JOIN ....
              +
              SELECT SUM(table.field) FROM tabledfsd INNER JOIN ....
              
              ) intermediate

//or simplier example

SELECT
                MAX(intermediate.test)
            FROM               
              (
              
              SELECT SUM(1+4)
              +
              SELECT SUM(2+6)
              
              ) intermediate


What is a correct syntax for this? Is even possible to calculate two selects inside subquery?

tnx!

I… think you’re looking at a UNION syntax… but perhaps you should explain what you’re trying to do - I have a sneaking suspicion you’re doing more work than you need to.

EDIT: Note to self, read which forum you’re in. Additional question: Which Database daemon are you using?

ernie, you forgot to assign a column alias in the subquery

plus, it really does sound like you want UNION ALL instead of “plus”

reason? because SUM() + SUM() gives one number as the answer, so why would you be wanting to take the MAX of a single number?

SELECT MAX(intermediate.[COLOR="blue"]test[/COLOR])
  FROM ( SELECT SUM(table.field) [COLOR="Blue"]AS test[/COLOR]
           FROM tabledfsd INNER JOIN ....
         UNION ALL
         SELECT SUM(table.field) 
           FROM tabledfsd INNER JOIN ....
       ) AS intermediate