Solved

How to turn multiple rows into one row in oracle without creating functions or views

Posted on 2014-03-14
3
605 Views
Last Modified: 2014-03-14
In my database, I have e.g following 2 rows

SSSN                           UNIT           INDV     PROF
330511-000      GYMBER01      INDV          NULL      
330511-000      GYMBER01      NULL          PROF

I want it displayed like this, that is: only one row

SSSN                           UNIT             INDV              PROF
330511-000      GYMBER01        INDV             PROF      




I know how to achieve this by Writing functions or multiple views which I then join, but I would also be good to be able to achieve this if I only have read-rights in the db.

This is the code that returns the first to rows:

select  ssn, UNIT,

case  when kurskod='INDV' then kurskod  end AS INDV,
case  when kurskod='PROF' then kurskod  end AS PROF

from aktivitet


Open in new window

0
Comment
Question by:marcgu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 450 total points
ID: 39929518
SELECT sssn,
         unit,
         MAX(CASE WHEN kurskod = 'INDV' THEN kurskod END) indv,
         MAX(CASE WHEN kurskod = 'PROF' THEN kurskod END) prof
    FROM aktivitet
GROUP BY sssn, unit
0
 
LVL 29

Assisted Solution

by:MikeOM_DBA
MikeOM_DBA earned 50 total points
ID: 39929524
The code you posted would not return two rows unless:

   1) The table contain duplicate ssn or
   2) You are either joining the table to itself or doing a UNION.

In any case you could use the MAX() function to eliminate the NULL columns.
0
 

Author Closing Comment

by:marcgu
ID: 39929541
Hi!

Great solutions. I give sdstuber most since it was posted first and complete.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question