Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

150
Visualizações
Set column value of a view based on which table I'm selecting from

I'm creating a view from 2 tables. I need to create a brand new column in the view; this column must be set to 0 when I'm selecting from the first table, 1 from the second one:

Table A:
+---------+---------+
|column A |column B |
+---------+---------+
|  Boston |   USA   |
+---------+---------+
| Chicago |   USA   |
+---------+---------+
|Las Vegas|   USA   |
+---------+---------+

Table B:
+---------+---------+
|column A |column B |
+---------+---------+
|  Paris  |  Europe |
+---------+---------+
|  Madrid |  Europe |
+---------+---------+
|  London |  Europe |
+---------+---------+

Resulting View:
+---------+---------+---------+
|column A |column B | column C|
+---------+---------+---------+
|  Boston |   USA   |    0    |
+---------+---------+---------+
| Chicago |   USA   |    0    |
+---------+---------+---------+
|Las Vegas|   USA   |    0    |
+---------+---------+---------+
|  Paris  |  Europe |    1    |
+---------+---------+---------+
|  Madrid |  Europe |    1    |
+---------+---------+---------+
|  London |  Europe |    1    |
+---------+---------+---------+
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Just use a union with a computed column:

SELECT columnA, columnB, 0 AS columnC FROM TableA
UNION ALL
SELECT columnA, columnB, 1 FROM TableB
ORDER BY columnC;
over 4 years ago · Santiago Trujillo Relatório

0

SELECT columnA, colunmB, 0 as columnC from tableA
UNION
SELECT columnA, colunmB, 1 as columnC from tableB,

it looks like you are using UNION to create the view. Then just add the dummy field in each sql

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda