Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!