Union query merging issue

harshadborde

Registered User.
Local time
Today, 08:49
Joined
Apr 10, 2017
Messages
17
I am facing a issue in Union query. I am trying to merge 2 query results. Both results have 6 columns. Last column is 'Salary0' in 1st query and 'Salary1' in 2nd

query. But after union, both are columns are getting merged under header of 'Salary0'. I want both to remain as separate columns. Help will be much appreciated.
 
They will do, that's the point of a union query
I could ask why merge them if they are different.

Anyway, add an extra field to each part:
Part 1 - add: Null AS Salary0
Part 2 - add: Null AS Salary1

Then your union query should show both columns
 
They will do, that's the point of a union query
I could ask why merge them if they are different.

Anyway, add an extra field to each part:
Part 1 - add: Null AS Salary0
Part 2 - add: Null AS Salary1

Then your union query should show both columns

I want to merge first 5 columns as they are similar. Last 6th one Salary0 & Salary1 are different.

Query0 - A | B | C | D | E | Salary0
Query1 - A | B | C | D | E | Salary1

Answer should be - A | B | C | D | E | Salary0 | Salary1

But its showing A | B | C | D | E | Salary0 with Salary1 records under salary0. Thats the problem.


My Query is

Select [A], ,[C],[D],[E], [Salary0] from Q0
Union
Select [A], ,[C],[D],[E], [Salary1] from Q4

How shall I change it?
 
You have 2 queries each with 6 columns.
You want a final query with 7 columns.
You must make your initial queries contain 7 columns.
Put in dummy columns into each query you have now to correspond with all the final columns you want in your query.

Further, UNION queries are generally hacks. Can you post the SQL of 2 initial queries. My guess is that you can logically do this in one SELECT statement.
 
As Plog said, you probably can do this from a suitable SELECT query but to repeat my first answer in more detail, this should do the trick:

Code:
Select [A], [B],[C],[D],[E], [Salary0], Null AS [Salary1] from Q0
Union
Select [A], [B],[C],[D],[E], Null AS [Salary0], [Salary1] from Q4
 
It is throwing some chinese characters(ᑺꮮ䁳) instead of value for 'Salary1'.
 

Users who are viewing this thread

Back
Top Bottom