Home » SQL & PL/SQL » SQL & PL/SQL » Retrieve data from a table based on column name specified in another table.
Retrieve data from a table based on column name specified in another table. [message #189381] Thu, 24 August 2006 06:26 Go to next message
psantha
Messages: 5
Registered: August 2006
Junior Member
Hi all,

The problem description is given below.

create table samp
(name varchar(15),
A varchar(20),
B varchar(20),
C varchar(20),
D varchar(20));


insert into samp
(name,A,B,C,D)
values ('x','Xa','Xb','Xc','Xd');

insert into samp
(name,A,B,C,D)
values ('y','ya','yb','yc','yd');

insert into samp
(name,A,B,C,D)
values ('z','xa','zb','zc','zd');

create table exp
(name varchar(15),
cname varchar(20));

insert into exp
(A,cname)
values ('xA','B');

insert into exp
(A,cname)
values ('yA','C');




Samp

Name A B C D
x xa xb xc xd
y ya yb yc yd
z xa zb zc zd


exp

A cname
ya C
xa B


The output i require is

Name <null>
y yc
x xb
z zb

The values in column 'cname' of table 'emp' refers to columns in table 'samp'. The second column name in the output can be anything.


The problem is I am not very sure how this can be done using query. Please can anybody guide me on this.

Re: Retrieve data from a table based on column name specified in another table. [message #189388 is a reply to message #189381] Thu, 24 August 2006 06:59 Go to previous messageGo to next message
gbarbisan
Messages: 67
Registered: August 2006
Location: Treviso - Italy
Member
Could this be a point to start from? Again credits to T. Kyte.
Re: Retrieve data from a table based on column name specified in another table. [message #189390 is a reply to message #189388] Thu, 24 August 2006 07:18 Go to previous message
psantha
Messages: 5
Registered: August 2006
Junior Member
Yes. I looked into this reference, given for another post. That was good.

But if i could know whether this can be done with a query and how, then it would be really useful.
Previous Topic: Problem with recreate table with primary key constraint
Next Topic: Materialized Views, Self Joins, Refresh on commit
Goto Forum:
  


Current Time: Tue Dec 06 12:06:27 CST 2016

Total time taken to generate the page: 0.06524 seconds