title: Insert into with union
body: <p>I have a problem. There are three tables: T1, T2, T_target. T1 and T2 table have many different columns but I need only the ID column from both. The T_target table has an ID column of course and another: project_No.</p>
  
  <p>There are some IDs which appears in T1 and T2 too, but I don't want to create duplicates between them, if an ID appears in both table it have to be inserted into the T_target only once but if it is already in the T_target it's allowed to act twice. The other of the criteria is every newly inserted ID must be value 21 in 'project_No' column. So, e.g.:</p>
  
  <p><strong>T1:</strong></p>
  
  <pre><code>ID
  2548
  2566
  2569
  2843
  2888
  ...
  </code></pre>
  
  <p><strong>T2:</strong></p>
  
  <pre><code>ID
  2557
  2566
  2569
  2700
  2913
  2994
  3018
  5426
  ...
  </code></pre>
  
  <p><strong>T_target:</strong></p>
  
  <pre><code>ID     project_No
  2976   1
  3331   7
  4049   7
  5426   8
  5915   3
  6253   10
  ...
  </code></pre>
  
  <p>And the result I want to see:</p>
  
  <p><strong>T_target:</strong></p>
  
  <pre><code>ID     project_No
  2548   21
  2557   21
  2566   21
  2569   21
  2700   21
  2843   21
  2888   21
  2913   21
  2976   1
  2994   21
  2018   21
  3331   7
  4049   7
  5426   8
  5426   21
  5915   3
  6253   10
  ...
  </code></pre>
  
  <p>So, I tried it with this code (it is important to be here "NOT NULL" criteria because both of T_target columns are primary key):</p>
  
  <pre><code>insert into T_target (ID, project_No)
    select (select ID
    from T1 where ID is not NULL
   union
    select ID
    from T2 where ID is not NULL), 21
  
  select * from T_target
  </code></pre>
  
  <p>The error message:
  <strong>"Msg 512, Level 16, State 1, Line 2
  Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, &lt;, &lt;= , >, >= or when the subquery is used as an expression.
  The statement has been terminated."</strong></p>
  
  <p>Then I tried with VALUES statement instead of the first SELECT and parentheses but the error is the same.</p>
  
  <p>There is a similar problem:
  <a href="https://stackoverflow.com/questions/2958235/mysql-query-how-to-insert-with-union">mySQL query: How to insert with UNION?</a>
  but this solution doesn't work for me because it indicates syntax error between VALUE and SELECT.</p>
  
  <p>Please, give me a hand.
  Thank you!</p>