Click here to Skip to main content
15,908,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I have three tables :maingroup, subgroup and mobile. I want to display all mobiles from all subgroups that belong to a specific main group.
How can I make that, please?
Thanks
SQL
alter proc mobile_select
(@maingroupid int)
as
begin
select mobile
from tbl_mobile, tbl_maingroup, tbl_subgroup
where
tbl_maingroup.maingroupId=@maingroupid  and
tbl_maingroup.maingroupId=tbl_subgroup.maingroupId
end
Posted
Updated 18-Jan-11 2:04am
v2
Comments
[no name] 18-Jan-11 8:10am    
Are you having any problems with this?
moon2011 18-Jan-11 8:11am    
it returns wrong data.
i mean that i returns all mobiles in all subgroups and main groups.

You forgot to give condition for tbl_mobile.
Unless you specify that condition, it will return all data.
 
Share this answer
 
You have not placed any condition for the Mobile table. Update the where clause and it will work.
 
Share this answer
 
SQL
alter proc <pre lang="sql">alter proc mobile_select
(@maingroupid int)
as
begin
select mobile
from tbl_mobile, tbl_maingroup, tbl_subgroup
where
tbl_maingroup.maingroupId=@maingroupid  and
tbl_maingroup.maingroupId=tbl_subgroup.maingroupId and
tbl_mobile.subgroupId=tbl_subgroup.subgroupId
end
 
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