Question

Asked on 2006-07-25 at 10:36:00ID: 25467898

Simple Oracle query for two tables

by: austerhaus300

Rating9.4Excellent

Hello,

I have an Oracle 8i db with two tables in it: QUESTION AND ANSWER. The QUESTION table stores a question id (ID) and the question text (TEXT). There are approximately 40 questions. The ANSWER table uses SESSION_ID to identify the user that submitted the answers, QUESTION_ID to tie it back to the QUESTION table and the answer that the user submitted. See below for a sample.


TABLE: QUESTION
 ID     TEXT                                                    
 -----  ---------------------------------------------------------
 1      What % of the time do you use the resources:            
 2      When searching, I find what I am looking for.            
 3      The solutions I find help me solve my problems.          
 4      I am able to effectively navigate through the resources.
 ...

TABLE: ANSWER
 SESSION_ID     QUESTION_ID     ANSWER
 -------------  --------------  -------
 auIoiuuJkh1=   1               30-50%
 auIoiuuJkh1=   2               Agree  
 auIoiuuJkh1=   3               Agree  
 auIoiuuJkh1=   4               Agree  
 EuioiuujkX1=   1               20-30%
 EuioiuujkX1=   2               Agree  
 EuioiuujkX1=   3               Agree  
 EuioiuujkX1=   4               Agree  
 ...

What I need is a query that displays each question as a column and the answers as rows, similar to that below:

SESSION_ID    QUESTION_1  QUESTION_2  QUESTION_3  QUESTION_4  ...
------------  ----------  ----------  ----------  ----------
auIoiuuJkh1=  30-50%      Agree       Agree       Agree
EuioiuujkX1=  20-30%      Agree       Agree       Agree
...


Please let me know if additional information is required. Thanks in advance.

  1. Need help with an Oracle Query with two tables
    I took out all the uneeded variables in the Jobs table. Nothing that was a Primary for foreign key, just stuff I needed to query. I already made a query to find a list of all the Jobs already filled which wasn't hard, now I'm trying to figure out how to use these two tables to find out all the jobs that aren't filled. Here is where I am so far. SELECT…
  2. Combining two Oracle queries into one; JOINING…
    Hello, Have the two queries listed below, need to combine the two if possible, each db has its own un/pw/connection. Is that possible? If not any thoughts how to combine the two before returning a result? Thanks
  3. how to setup table replication in two directions w…
    Does anyone know how to setup Oracle stream or know some links how to do it?
  4. table question
    A junior and quick Oracle question. I have a table, and now my application needs to add a new field to this table. But this table is used in various components like this: INSERT INTO log (action, action_time, table_name, old_content, new_content, os_user) VALUES (v_ChangeType, SYSDATE, 'test', v_Old_Content, v_…
  5. Performance Issue
    Hi Foloowing two sql causing performance issue in production. SELECT QUESTION_ID, OPTION_ID, COUNT (OPTION_ID) COUNT FROM RESPONSES WHERE SURVEY_ID = ? GROUP BY QUESTION_ID, OPTION_ID ORDER BY QUESTION_ID From above query we QUESTION_ID, OPTION_ID SURVEY_ID are foreign keys and each …

Solution

Sign up now to view this solution! It's quick, easy, and secure to subscribe. We will return you to this solution, unlocked, when you’re done.

About this Solution
View This Solution - Start Your 30 Day Free Trial
Zone
General
Tags
oracle query two tables simple
Participating Experts
2
Solution Grade
A

Replies

 by: jrb1

Posted on 2006-07-25 at 13:48:56ID: 28282735

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: austerhaus

Posted on 2006-07-25 at 16:21:49ID: 28282736

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by:

Posted on 2006-07-25 at 16:28:16ID: 28282737

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: sathyagiri

Posted on 2006-07-25 at 16:56:19ID: 28282738

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: austerhaus

Posted on 2006-07-25 at 17:27:22ID: 28282739

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

Stay Connected

Oracle Around the Web

The latest Oracle news, tips, and tricks

Oracle Unveils Netra SPARC T3 Servers

New Carrier-Grade Blade and Rackmount Servers Deliver Better Performance, Density and Power Efficiency for the Communications Industry ...

read more

Oracle fixes 21 flaws in Java SE, Java for Business

Oracle is fixing 21 flaws in its Java SE and Java for Business products in its February critical patch update issued this week ...

read more

Obama’s Silicon Valley “Tech Supper”

Why was he there? Who wasn’t invited and why? What did they talk about? Why was he really there? These are the questions being debated ...

read more

Featured Oracle Experts

slightwv

slightwv has answered more than 2,000 Oracle questions and oversees database management within the U.S. Government. Slightwv

sdstuber

A regular presenter at the Collaborate conference, Oracle developer sdstuber is a top expert in PL/SQL and Oracle 9, 10 and 11. sdstuber

Testimonials

What users are saying about our experts

"The Oracle gurus provide answers, solutions and valuable workarounds"

User: schwertner

"Wow! Excellent, valuable explanation. Hats off to you"

User: aseshu70

"Solution worked fantastic and performs excellent! Thanks heaps"

User: klausbrandlhuber

Top Experts

  1. slightwv

    2,000

    0 points yesterday

    Profile

BrowseBecome an Expert