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?
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.
UNIONand theORDER BYstatement?