Click here to Skip to main content
15,898,373 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi to all!

i want to create a querry to get info from multiple tables
here is my data


table 1
a1, b1

table 2
a1, a2, b2, c2, d2

table 3
a2, a3

table 4
b2, b4

table 5
c2, c5



given is only b1
but i have to display a1, a3, b4, c5
Posted
Comments
MallikarjunaGupta 18-Aug-11 1:15am    
can u explain clearly.
a1 is common to table1 and table2
but a3,b4,c5 is not common any table.
actually what u want?
kami124 18-Aug-11 3:20am    
this is my actual querry but its just displaying column names but i need field values over ther as well what i am missing in the querry
can u check


select [sec_umrf_details].mrfno_nu, [sec_modules].modname_vc,
[sec_roles].rolename_vc, [sec_functions].functionname_vc

from [sec_umrf_details]

join [sec_mrf_details] on [sec_umrf_details].mrfno_nu = [sec_mrf_details].mrfno_nu
join [sec_modules] on [sec_mrf_details].modid_int = [sec_modules].modid_int
join [sec_roles] on [sec_mrf_details].roleid_int = [sec_roles].roleid_int
join [sec_functions] on [sec_mrf_details].fnid_int = [sec_functions].fnid_int

where [sec_umrf_details].userid_vc = 'iagsa'

Try joins
SQL
select t1.a1, t3.a3, t4.b4, t5.c5
from t1 
  join t2 on t1.a1 = t2.a1
  join t3 on t2.a2 = t3.a2
  join t4 on t2.b2 = t4.b2
  join t5 on t2.c2 = t5.c2
where t1.b1 = @b1
 
Share this answer
 
Comments
kami124 18-Aug-11 1:38am    
this is my actual querry but its just displaying column names but i need field values over ther as well what i am missing in the querry
can u check


select [sec_umrf_details].mrfno_nu, [sec_modules].modname_vc,
[sec_roles].rolename_vc, [sec_functions].functionname_vc

from [sec_umrf_details]

join [sec_mrf_details] on [sec_umrf_details].mrfno_nu = [sec_mrf_details].mrfno_nu
join [sec_modules] on [sec_mrf_details].modid_int = [sec_modules].modid_int
join [sec_roles] on [sec_mrf_details].roleid_int = [sec_roles].roleid_int
join [sec_functions] on [sec_mrf_details].fnid_int = [sec_functions].fnid_int

where [sec_umrf_details].userid_vc = 'i-jadoon'
TRY OUT THIS QUERY........

SELECT t1.a1, t3.a3, t4.b4, t5.c5
FROM table1 t1, table2 t2, table3 t3, table4 t4, table5 t5
WHERE t1.b1= 'b1' AND t1.a1=t2.a2 AND t2.a2=t3.a2 AND t2.b2=t4.b2 AND t2.c2=t5.c2



HASSAN TARIQ
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900