Click here to Skip to main content
12,405,303 members (66,972 online)
Rate this:
 
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
Updated 19-Dec-12 20:47pm
v4
Comments
__TR__ 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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160721.1 | Last Updated 21 Dec 2012
Copyright © CodeProject, 1999-2016
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