Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi to all!
i create two querries
in querry1's where condition i want to add querry2
querry1 is to show only one record
and by adding querry2 to querry1 it will show multiples rows

query1
SQL
ALTER procedure [dbo].[proc_mrf_discription_user1] (@mrfid int)
as
select sec_modules.modname_vc, 
	   sec_roles.rolename_vc, 
	   sec_functions.functionname_vc
from sec_umrf_details
left join sec_mrf_details on sec_umrf_details.mrfno_int = sec_mrf_details.mrfno_int
left join sec_modules on sec_modules.modid_int = sec_mrf_details.modid_int
left join sec_roles on sec_roles.roleid_int = sec_mrf_details.roleid_int
left join sec_functions on sec_functions.fnid_int = sec_mrf_details.fnid_int

where 

sec_mrf_details.mrfno_int = (@mrfid)

group by sec_modules.modname_vc, sec_roles.rolename_vc, sec_functions.functionname_vc

instead of this "sec_mrf_details.mrfno_int = (@mrfid)"
i want to add querry2 but remember querry2 has multiple rows
query2
SQL
select sec_umrf_details.mrfno_int from sec_umrf_details
where userid_vc = 'asda'
Posted
Updated 23-Aug-11 21:02pm
v2
Comments
Prerak Patel 24-Aug-11 3:02am    
Format your question properly. Use code block for code segments.

Simplest way with a quick read of the question is to use nested query (it is not advisable generally though).

SQL
select columns from table where someColumn in (select someColumn from table where someCondition)


Another way will be too use proper joins. This is will be more efficient than former.
 
Share this answer
 
Comments
Toniyo Jackson 24-Aug-11 3:50am    
Correct solution, 5!
Try this.
ALTER procedure [dbo].[proc_mrf_discription_user1] (@mrfid int)
as
select sec_modules.modname_vc, 
	   sec_roles.rolename_vc, 
	   sec_functions.functionname_vc
from sec_umrf_details
left join sec_mrf_details on sec_umrf_details.mrfno_int = sec_mrf_details.mrfno_int
left join sec_modules on sec_modules.modid_int = sec_mrf_details.modid_int
left join sec_roles on sec_roles.roleid_int = sec_mrf_details.roleid_int
left join sec_functions on sec_functions.fnid_int = sec_mrf_details.fnid_int
 
where 
 
sec_mrf_details.mrfno_int IN (select sec_umrf_details.mrfno_int from sec_umrf_details
where userid_vc = 'asda')
 
group by sec_modules.modname_vc, sec_roles.rolename_vc, sec_functions.functionname_vc
 
Share this answer
 
Comments
kami124 24-Aug-11 6:07am    
thanks
Absolutly right
Toniyo Jackson 24-Aug-11 6:15am    
You are welcome :)
If you want to accumulate the result of two queries that return similar results, you can use the UNION operation.

As an example, see this
SQL
select sec_modules.modname_vc, 
	   sec_roles.rolename_vc, 
	   sec_functions.functionname_vc,'',''
from sec_umrf_details
left join sec_mrf_details on sec_umrf_details.mrfno_int = sec_mrf_details.mrfno_int
left join sec_modules on sec_modules.modid_int = sec_mrf_details.modid_int
left join sec_roles on sec_roles.roleid_int = sec_mrf_details.roleid_int
left join sec_functions on sec_functions.fnid_int = sec_mrf_details.fnid_int
where 
sec_mrf_details.mrfno_int = (@mrfid)
group by sec_modules.modname_vc, sec_roles.rolename_vc, sec_functions.functionname_vc
UNION
select '','','',sec_umrf_details.mrfno_int from sec_umrf_details
where userid_vc = 'asda'
 
Share this answer
 
v2
Comments
kami124 24-Aug-11 3:15am    
i think you didnt read my question properly how they are similsr

now listen querry 2 i will get @mrfid

and by that mrfid querry 1 wil display complete row

so in querry2 we have more then one values
select field1.Table1, field1.Table2 from Table1 Leftjoin Table2 on field.Table1=field.Table2
 
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