1

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?

1
  • I'm not totally sure if I got the question, but have you looked into the UNION and the ORDER BY statement? Commented Sep 14, 2013 at 9:58

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.