Creating new variables in MS Access and Union Query

  • Thread starter Thread starter jlmr
  • Start date Start date
J

jlmr

Given 2 MS Access tables: table1 and table2

In table1 are the following 2 variable names: ABC and XYZ with 50
records.
In table2 are the following 3 variable names: ABC, XYZ and TTT with 25
records.

Is it possible to write a ms sql program that will:
[1.] Create a new variable called 'TTT' for table1, thus matching the
variables in table2
[2.] Then be able to write a UNION query that will append all 50 + 25 =
75 records into one output.

Note: One of the conditions for using a UNION query is that the fields
must be the same.

Example:

SELECT XYZ, ABC
FROM Table1

UNION SELECT XYZ, ABC, TTT
FROM Table2

NOTICE: IN THE ABOVE EXAMPLE, THE VARIABLE 'TTT' IS MISSING FROM
TABLE1. THEREFORE THIS QUERY WILL NOT RUN CORRECTLY. IT NEEDS ANOTHER
STEP WHICH IS THE QUESTION I AM SEEKING...CAN WE CREATE A NEW VARIABLE
CALLED TTT FOR TABLE1 AND WHAT IS THE CODE TO DO THAT...
 
SELECT XYZ, ABC, null AS TTT
FROM Table1

UNION ALL SELECT XYZ, ABC, TTT
FROM Table2
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top