Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8403337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:19:00+00:00 2026-06-09T22:19:00+00:00

I have a table which is not normalized and I can’t change the structure

  • 0

I have a table which is not normalized and I can’t change the structure of the table. The table contains 6 columns to hold preferences namely preference_num1…preference_num6. I want to extract data from table so that it looks like there are 6 rows with one preference being in one row.

To make it clear, the output should be Id,semester_start,year_start,email,preference_num. And, each row would be broken into 6 rows .

Name                    Null     Type          
----------------------- -------- ------------- 
ID                               number (primary key)
YEAR_START                       NUMBER        
SEMESTER_START                   VARCHAR2(8)   
EMAIL                            VARCHAR2(100) 
PREFERENCE_NUM_1                 VARCHAR2(1)   
PREF_INSTITUTION_NAME_1          VARCHAR2(100) 
PREF_INSTITUTION_CODE_1          VARCHAR2(15)  
PREF_COURSE_TITLE_1              VARCHAR2(100) 
COURSE_CODE_1                    VARCHAR2(15)  
OFFERING_LABLE_1                 VARCHAR2(15)  
PREFERENCE_NUM_2                 VARCHAR2(1)   
PREF_INSTITUTION_NAME_2          VARCHAR2(100) 
PREF_INSTITUTION_CODE_2          VARCHAR2(15)  
PREF_COURSE_TITLE_2              VARCHAR2(100) 
COURSE_CODE_2                    VARCHAR2(15)  
OFFERING_LABLE_2                 VARCHAR2(15)  
PREFERENCE_NUM_3                 VARCHAR2(1)   
PREF_INSTITUTION_NAME_3          VARCHAR2(100) 
PREF_INSTITUTION_CODE_3          VARCHAR2(15)  
PREF_COURSE_TITLE_3              VARCHAR2(100) 
COURSE_CODE_3                    VARCHAR2(15)  
OFFERING_LABLE_3                 VARCHAR2(15)  
PREFERENCE_NUM_4                 VARCHAR2(1)   
PREF_INSTITUTION_NAME_4          VARCHAR2(100) 
PREF_INSTITUTION_CODE_4          VARCHAR2(15)  
PREF_COURSE_TITLE_4              VARCHAR2(100) 
COURSE_CODE_4                    VARCHAR2(15)  
OFFERING_LABLE_4                 VARCHAR2(15)  
PREFERENCE_NUM_5                 VARCHAR2(1)   
PREF_INSTITUTION_NAME_5          VARCHAR2(100) 
PREF_INSTITUTION_CODE_5          VARCHAR2(15)  
PREF_COURSE_TITLE_5              VARCHAR2(100) 
COURSE_CODE_5                    VARCHAR2(15)  
OFFERING_LABLE_5                 VARCHAR2(15)  
PREFERENCE_NUM_6                 VARCHAR2(1)   
PREF_INSTITUTION_NAME_6          VARCHAR2(100) 
PREF_INSTITUTION_CODE_6          VARCHAR2(15)  
PREF_COURSE_TITLE_6              VARCHAR2(100) 
COURSE_CODE_6                    VARCHAR2(15)  
OFFERING_LABLE_6                 VARCHAR2(15)  
DATA_EXTRACTION_DATE             DATE          
OFFER_DATE_1                     DATE          
OFFER_RESPONSE_1                 VARCHAR2(20)  
FINAL_OFFER_RESPONSE_1           VARCHAR2(20)  
OFFER_DATE_2                     DATE          
OFFER_RESPONSE_2                 VARCHAR2(20)  
FINAL_OFFER_RESPONSE_2           VARCHAR2(20)  
OFFER_DATE_3                     DATE          
OFFER_RESPONSE_3                 VARCHAR2(20)  
FINAL_OFFER_RESPONSE_3           VARCHAR2(20)  
OFFER_DATE_4                     DATE          
OFFER_RESPONSE_4                 VARCHAR2(20)  
FINAL_OFFER_RESPONSE_4           VARCHAR2(20)  
OFFER_DATE_5                     DATE          
OFFER_RESPONSE_5                 VARCHAR2(20)  
FINAL_OFFER_RESPONSE_5           VARCHAR2(20)  
OFFER_DATE_6                     DATE          
OFFER_RESPONSE_6                 VARCHAR2(20)  
FINAL_OFFER_RESPONSE_6           VARCHAR2(20)  

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T22:19:01+00:00Added an answer on June 9, 2026 at 10:19 pm

    You might find more information about this if you search for UNPIVOT techniques or “oracle columns to rows”.

    One way of doing this is as below, which works well if you are inputting one (indexed) id. I am getting only 3 of the preferences to keep the example simple.

    This is the basic idea.

    select id, sem_start, year_start, pref_num1 from table_1 where id = input_id
    union all 
    select id, sem_start, year_start, pref_num2 from table_1 where id = input_id
    union all
    select id, sem_start, year_start, pref_num3 from table_1 where id = input_id
    

    You should use this query instead, which would be more performant, since we are querying by id only once.

    with t1 as
    (select * from table_1 where id = id1)
    select id, sem_start, year_start, pref_num1 from t1
    union all 
    select id, sem_start, year_start, pref_num2 from t1
    union all
    select id, sem_start, year_start, pref_num3 from t1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table in mysql which is not normalized and I need to
I have table which contains double values stored in mysql database ...I need to
I have one table which contains events and dates, and another which contains the
I have a table which contains TV Guide data. In a simplified form, the
I have to maintain an old database which is not properly normalized. For instance
I have this table which contains a field called 'icon_for' which I have been
I have table which contains the rows that are dynamic from server side scripting(PHP)
I have one very large, un-normalized table which I am in the process of
I have six tables, which unfortunately does not have any primary/foreign key-relations encoded. I've
I have table in which I am inserting rows for employee but next time

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.