i have three database tables.
table1 consists (townid as pk,town name)
table2 consists (phase id as pk,townid ad ck, and phase name)
table3 consists(sectorid as pk,townid ad ck,phaseid as ck, and sector name)
i want to show a gridview, in that gridview i want to show data of table3, but i want that it shows me the secto name, town name, and phase name instead of showing the ids. how is it possible????
Loading
Posted May 31, 2011, 10:48 AM
select
t.TownName,
p.PhaseName,
s.sectorName
from
Town t
inner join Phase p on t.TownID = p.TownID
inner join Sector s on s.TownId = t.TownID and s.PhaseID = p.PhaseID
Based on the primary key and foreign key, create a join between three tables.
Please let me know, still if you're got the answer.
saifullah khanPosted May 31, 2011, 10:57 AM
saifullah khanPosted May 31, 2011, 10:45 AM
Posted May 31, 2011, 8:40 AM
select
t.TownName,
p.PhaseName,
s.sectorName
from
Town t inner join Phase p on t.TownID = p.TownID
inner join Sector s on s.TownId = t.TownID and s.PhaseID = p.PhaseID
According to your data, alter the joins if you want.
I haven't tested the syntax and typed directly here.