Click here to Skip to main content
11,648,094 members (65,186 online)
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 jyo.net 500
1 F-ES Sitecore 370
2 DamithSL 300
3 OriginalGriff 277
4 CPallini 250
0 OriginalGriff 1,342
1 jyo.net 994
2 DamithSL 981
3 Sergey Alexandrovich Kryukov 893
4 CPallini 845


Advertise | Privacy | Mobile
Web02 | 2.8.150804.4 | Last Updated 21 Dec 2012
Copyright © CodeProject, 1999-2015
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