Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-Server
my first query is not working and second is working but i want to search a member through group id
 

select m.mId,(mFName+' '+isnull(mLName,'')) as mname,s.subCatName,s.subCatId,
 mAdd,
   mContact,mCity,mFather,mQual from tblMemberDetail m
 inner join tblMemberCourse c on m.mId=c.mId
 inner join tblSubCategory s on c.subcatId=s.subCatId
 where mActive = 1 and m.mId=1
 

select m.mId,(mFName+' '+isnull(mLName,'')) as mname,
g.gName, mAdd,
   mContact,mCity,mFather,mQual from tblMemberDetail m
 inner join tblMemberCourse c on m.mId=c.mId
 inner join tblGroup g on c.gId=g.gId
 where mActive = 1 and m.mId=1
Posted 19-Dec-12 20:23pm
Edited 19-Dec-12 20:47pm
v4
Comments
__TR__ at 20-Dec-12 2:57am
   
What do you mean by "not working" ? Are you getting any error ?
We need some more details on what is it you are trying to do.
PeanutB at 20-Dec-12 3:13am
   
Have you checked that the subcatId returned by tblMemberCourse actually exists in tblSubCategory?
 
More info

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
Both the Query are ok ,
 
In case if Query is not returning any row then possible reason is that
tblSubcategory don't have record for MemberID : 1 ;
 
you may use left join in such case as
 
select m.mId,(mFName+' '+isnull(mLName,'')) as mname,s.subCatName,s.subCatId,
 mAdd,
   mContact,mCity,mFather,mQual from tblMemberDetail m
 inner join tblMemberCourse c on m.mId=c.mId
 left join tblSubCategory s on c.subcatId=s.subCatId
 where mActive = 1 and m.mId=1
 
Thanks !
Yogendra Dubey
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 568
1 OriginalGriff 384
2 George Jonsson 258
3 Abdul Samad KP 135
4 Animesh Datta 130
0 OriginalGriff 6,099
1 Sergey Alexandrovich Kryukov 5,411
2 CPallini 4,770
3 George Jonsson 3,400
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 21 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100