mysql - union with creating demarcated field

Posted by Qiao on Stack Overflow See other posts from Stack Overflow or by Qiao
Published on 2010-03-24T19:56:27Z Indexed on 2010/03/24 20:03 UTC
Read the original article Hit count: 270

Filed under:

I need UNION two tables with creating new field, where 1 for first table, and 2 for second.

I tried

(
    SELECT field, 1 AS tmp
    FROM table1
)
UNION
(
    SELECT field, 2 AS tmp
    FROM table2
)

But in result, tmp field was full of "1".

How it can be implemented?

© Stack Overflow or respective owner

Related posts about mysql