2 Replies Latest reply on Jul 26, 2015 7:17 PM by alejandro.banderas@me.com

    Using UNION ALL with Aggregate Function in ExecuteSQL

    DerekHoiem

      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?