user2778933
user2778933

Reputation: 11

Getting Different column values from Multiple tables in SQL Server

I have following data in SQL Server tables:

id  Sal
1   100
2   200

id  Wages
1   600
2   800

I want the output as following:

id   Sal/Wages
1    100
1    600
2    200
2    800

How I can do that using a SELECT statement in SQL Server?

Upvotes: 1

Views: 56

Answers (2)

roman
roman

Reputation: 117400

use union all:

select id, sal as [sal/Wages] from table1
union all
select id, wages as [sal/Wages] from table2
order by 1

Note that I've used union all and not union, because union removes duplicates from resulting set. Sometimes it might be useful, but not in your case, I think.

Upvotes: 1

Kaf
Kaf

Reputation: 33829

Use UNION ALL

Select Id, sal as [sal/wages]
from table1
UNION ALL
Select Id, wages as [sal/wages]
from table2
Order by id,[sal/wages]

If you don't need duplicate records then just use UNION

Upvotes: 2

Related Questions