AnsweredAssumed Answered

Using UNION ALL with Aggregate Function in ExecuteSQL

Question asked by DerekHoiem on Feb 2, 2014
Latest reply on Jul 26, 2015 by alejandro.banderas@me.com

Title

Using UNION ALL with Aggregate Function in ExecuteSQL

Post

     I'm wondering why this ExecuteSQL statement is giving me a syntax error...

     SELECT SUM(units_sold) AS SumOfUnits, SUM(total_earned) AS SumTotalEarned
     FROM (
     SELECT units_sold, total_earned
     FROM table1
     UNION ALL       
     SELECT quantity AS units_sold, subtotal AS total_earned
     FROM table2 ) 
      
     I'm following the example exactly from this article... http://www.upsizing.co.uk/Art17_UnionQuery.aspx
      
     I've been able to use UNION ALL in other ExecuteSQL statements, but when I try to aggregate data across the UNION, filemaker is giving me a syntax error.  This is correct SQL, is it not?

Outcomes