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 |
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.
|
|
|
|
|
Goto Forum:
Current Time: Sat Dec 07 02:45:30 CST 2024
|