title: mySQL : Syntax Error "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to
body: <p>I'm trying to perform an outer left join from two subsets, order the results and then inject it into an existing table (append).
  I can't get why it's an unacceptable SQL query:</p>
  <pre><code>INSERT INTO f_grades ( tenant_code, 
                         effective_date, 
                         member_id, 
                         segment_code, 
                         ps_grade 
                        )
  (
   SELECT TT.*
   FROM (
         SELECT T.tenant_code as tenant_code,
                COALESCE(T.effective_date, CURRENT_DATE()) as effective_date,
                T.member_id as member_id,
                T.segment_code as segment_code,
                T.ps_grade as ps_grade
         FROM (
                 (
                   SELECT tenant_code, 
                          member_id, 
                          segment_code
                   FROM f_grades
                   WHERE effective_date = ( select MAX(DATE(effective_date)) from f_grades )
                    ) as A
                      LEFT OUTER JOIN
                  (
                    SELECT partner_member_id, 
                           effective_date, 
                           ps_grade
                    FROM touchpoint.PT_Flags
                   ) as B  on A.member_id = B.partner_member_id
               ) as T
        ) as TT
  );
  </code></pre>
  <p>The output error:</p>
  <pre><code>[2021-12-09 22:38:42] [42000][1064] (conn=1151) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'T
  [2021-12-09 22:38:42] [42000][1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'T
  [2021-12-09 22:38:42] ) as TT
  [2021-12-09 22:38:42] )' at line 15
  </code></pre>
  <pre><code>can please someone advise? 
  </code></pre>