Solved

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

Posted on 2014-03-14
3
598 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
3 Comments
 
LVL 73

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Pl/SQL Query 31 76
JDeveloper 12c for 32 bit 4 71
Dataware house query tuning 9 65
help on oracle query 5 33
Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
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 videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

896 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now