sql - select column with union and insert into table with remaining columns handpicked -


tablea => (columna , columnb, columnc , columnd ) 

i had select columna tablea based on union condition below.

select columna tablea columnb = 'x' union select columna tablea columnb = 'y'  output:  columna   123, 456, 789, 543 

how write sql query can insert columna unionquery above , columnb, columnc , columnd should hardcoded (eg: a, b, c)

expected output:

columna , columnb, columnc , columnd 123, a, b, c 456, a, b, c 789, a, b, c 543, a, b, c 

just use literal value , alias

  select columna, 'b' columnb, 'c' columnc, 'd' columnd     tablea columnb = 'x'   union   select columna, 'b', 'c', 'd' columnd    tablea columnb = 'y' 

and insert

  insert tablea (columna, columnb, columnc, columnd)    select columna, 'b' columnb, 'c' columnc, 'd' columnd    tablea columnb = 'x'   union   select columna, 'b', 'c', 'd' columnd   tablea columnb = 'y' 

Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -