26.6.09

Records in the first table based on the second table reference

Hi All,

Today, am trying to fetch a record from the first table and replace the values with the reference records in the second table. Let's make a try. There will be lot of ways to do this, am taking a legacy method to arrive the same. Let's see,

create table venkat(id int, id1 int, nam varchar(100))
insert into venkat values(1,2,'arun')
insert into venkat values(2,null,'arun1')
insert into venkat values(1,3,'arun2')
select * from venkat
create table venkat1(id int, val varchar(100))
insert into venkat1 values(1,'A')
insert into venkat1 values(2,'B')
insert into venkat1 values(3,'C')
select * from venkat1








select t1.val as id,t.val as id1,t.nam from
(
select b.val,a.nam from venkat a left outer join venkat1 b
on a.id1=b.id
)t inner join
(
select b.val,a.nam from venkat a left outer join venkat1 b
on a.id=b.id
)t1
on t.nam=t1.nam





Happy Learning!!!

Thanks and Regards,
Venkatesan Prabu .J

No comments:

Post a Comment