Search code examples
sqlcompiler-flags

How to add flag variable based on source


I want to union two tables and add a flag column(1,0) indicating where they came from. Any help on how to perform this SQL?


Solution

  • Just add a static column to your SELECT

    SELECT
        a
        ,b
        ,0 AS flag
    FROM
        t1
    UNION ALL
    SELECT
        a
        ,b
        ,1 AS flag
    FROM
        t2