How can I add a column to this union result?

Posted by MrXexxed on Stack Overflow See other posts from Stack Overflow or by MrXexxed
Published on 2010-06-11T16:56:33Z Indexed on 2010/06/11 17:02 UTC
Read the original article Hit count: 137

Filed under:
|

I have this query (which I removed some keys from for brevity's sake):

SELECT id as in_id, out_id, recipient, sender, read_flag 
  FROM received WHERE recipient=1
UNION ALL 
SELECT in_id, id AS out_id, recipient, sender, read_flag  
  FROM sent WHERE sender=1 

Which combines the results from two tables showing messages sent and received by a given user. What I'd like to do is add a column/flag to the result to distinguish which table the row belongs to so when I display them I can show a relevant icon for sent or received messages. How would I add this?

© Stack Overflow or respective owner

Related posts about mysql

Related posts about union