?
Solved

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

Posted on 2014-03-14
3
Medium Priority
?
609 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 1800 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 200 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

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…
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to recover a database from a user managed backup
Suggested Courses

777 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