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!

Oracle Interview Question. A bit confusing.

484123May 18 2006 — edited May 25 2006
Hi folks,
Recently, I went for a Oralce walk-in drive programme and here is one of the questions that kept me on tenterhooks.

First, let us say we have with us two tables A (Master) and B (Detail).

Table A
QID TEXT
--------------------------
1 What is the capital of USA?
2 ................
.
.
--------------------------

Table B
QID AID ANSWERS
----------------------------------------------------
1 1 Bush
1 2 Clinton
1 3 Reagon
1 4 Lincoln
2 5 .................
2 6 ................
2 7 ................
2 8 ................
3 9 ................
------------------------------------------------------

So, by now you might have got the idea on how these two tables work.
A is the master which contains the QID, primary key, and Text column contains the question.
Where as B has got it own Primary key AID, QID is the foreign key and the last column 'Answers' contain the four answers for the question.

Now we are given a third table C wherein we are supposed to insert the data from the above two tables in the following fashion. Note that only one record per question is allowed in this table. This tables has got no references to any of the above two tables.

Table C
QID | Text | A | B | C | D
------------------------------------------------------------------------------------------------------------
1 | Who is the president of USA? | Bush | Clinton | Reagon | Lincoln
2 ............................................... ........ ....... ....... .......

-------------------------------------------------------------------------------------------------------------

So we need to insert the data into the above C table in the above fashion from the two tables.
First I was asked to do it with the help of PL/SQL.
I could do it successfully in a step-by-step manner.
Later I was asked to insert into table C with the help of one statement only.
This was something that bamboozled me completely.

So, guys if you know the solution. please tell me whether it is PL/SQL, i could compare your solution with mine, and if you have got the solution with one statement, please do reply.

Your favour will be deeply appreciated,

Cheers
PCZ.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 22 2006
Added on May 18 2006
22 comments
1,175 views