Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

How can I write a query to get the result below from the sample data given?

Data in table EMP is as below:

Empid   Empname Sal Comm
100 ABC Null    20
100 ABC 20000   null

Output should be:

Empid   Empname Sal Comm
100 ABC 20000   20
share|improve this question

closed as off-topic by ypercube, David Spillett, JNK Apr 10 '14 at 14:51

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Too localized - this could be because your code has a typo, basic error, or is not relevant to most of our audience. Consider revising your question so that it appeals to a broader audience. As it stands, the question is unlikely to help other users (regarding typo questions, see this meta question for background)." – David Spillett, JNK
If this question can be reworded to fit the rules in the help center, please edit the question.

Why can't you do this yourself? What attempt have you made?! –  Mark Sinkinson Apr 10 '14 at 10:58
As it's currently written, this is a "black box" question. Unless you can give us some LOGIC behind your desired results, this doesn't really fit the purpose of this site. Please feel free to expand/clarify and flag this for reopening. –  JNK Apr 10 '14 at 14:52

1 Answer 1

select empid, 
       sum(sal) as sal,
       sum(comm) as comm
from emp
group by empid, empname;
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.