title: UNION ALL - return from which table the result is
body: <p>I have this code running (Thanks to @Gordon Linoff).</p>
  
  <pre><code>SELECT alid, max(ts) as ts
  FROM ((SELECT AL.alID, AL.al_date AS ts FROM AL)
        UNION ALL
        (SELECT MRA.mraNR, MRA.add_date FROM MRA)
        UNION ALL
        (SELECT AMG.mraNR, AMG.lastupd FROM AMG)
       ) t
  GROUP BY alID
  ORDER BY ts DESC
  LIMIT 20;
  </code></pre>
  
  <p>Now we need to have a third value, knowing from which table the result comes (AL, MRA or AMG).
  Already tried options like this, but nothing seems to work.</p>
  
  <pre><code>SELECT alid, TABLEVALUEWENEED as RES, max(ts) as ts
  FROM ((SELECT AL.alID, TABLEVALUEWENEED AS RES1, AL.al_date AS ts FROM AL)
        UNION ALL
        (SELECT MRA.mraNR, TABLEVALUEWENEED AS RES2, MRA.add_date FROM MRA)
        UNION ALL
        (SELECT AMG.mraNR, TABLEVALUEWENEED AS RES3, AMG.lastupd FROM AMG)
       ) t
  GROUP BY alID
  ORDER BY ts DESC
  LIMIT 20;
  </code></pre>
  
  <p>And, to get those tables values as php output like:</p>
  
  <pre><code>$RES1=$rows["RES1"];
  </code></pre>
  
  <p>Any help is appreciated!</p>