Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to display rows of data into different columns?

JoelSeahNov 11 2013 — edited Nov 12 2013

I'm new to SQL and currently this is what I'm trying to do: 

Display multiple rows of data into different columns within the same row

I have a table like this:

    CREATE TABLE TRIPLEG(

        T#              NUMBER(10)      NOT NULL,

        LEG#            NUMBER(2)       NOT NULL,

        DEPARTURE       VARCHAR(30)     NOT NULL,

        DESTINATION     VARCHAR(30)     NOT NULL,

        CONSTRAINT TRIPLEG_PKEY PRIMARY KEY (T#, LEG#),

        CONSTRAINT TRIPLEG_UNIQUE UNIQUE(T#, DEPARTURE, DESTINATION),

        CONSTRAINT TRIPLEG_FKEY1 FOREIGN KEY (T#) REFERENCES TRIP(T#) );

    INSERT INTO TRIPLEG VALUES( 1, 1, 'Sydney', 'Melbourne');

    INSERT INTO TRIPLEG VALUES( 1, 2, 'Melbourne', 'Adelaide');

The result should be something like this:

> T#  | ORIGIN  | DESTINATION1  |  DESTINATION2 

> 1   | SYDNEY  | MELBORUNE     | ADELAIDE

The query should include the `COUNT(T#) < 3` since I only need to display the records less than 3. How can I achieve the results that I want using relational views???

Thanks!!!

This post has been answered by JoelSeah on Nov 12 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 10 2013
Added on Nov 11 2013
16 comments
1,434 views