Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have 3 tables in my Database tblUserInfo, tblVisitor and third one tblInterest

table tblUserInfo Contains User Information along with primary key UserID.
table tblVisitor contains VisitorId and VistedProfileId
VisitorId and VisitedProfileId nothing but UserID in tblUserInfo

Table tblInterest Contain InterestFrom_UserID and InterestIn_UserID and InterestStatus


I want to get Details of user from tblUserInfo,
But those user are in tblVisitor
And get InterestStatus from tblInterest

the table tblInterest may or may not contain record matches to VisitorID
I want
if table tblInteres not contain record matches to visitorID then I want null value in InterestStatus Field.

What I have tried:

My query as follow


SQL
SELECT tblUserInfo.UserAutoID, tblVisitor.VisitedProfileUserAutoId, tblUserInfo.UserFirstName, tblUserInfo.ProfileID,
		YEAR(GETDATE())-YEAR(UserDOB) AS UserDOB,tblUserInfo.Height,tblUserInfo.Religion, tblUserInfo.Education,
		tblUserInfo.Occupation, tblUserInfo.ProfilePicPath, tblInterest.InterestStatus
		FROM
		tblVisitor INNER JOIN tblUserInfo 
		ON 
		tblVisitor.VisitorAutoID=tblUserInfo.UserAutoID 
		JOIN tblInterest
		ON 
		tblVisitor.VisitorAutoID=tblInterest.InterestIn
		WHERE
		tblVisitor.VisitedProfileUserAutoId=@VisitedProfileUserAutoId
		AND
		tblVisitor.VisitorAutoID=tblInterest.InterestIn
		AND
		tblVisitor.IsDeleted=0


When I fire above query I get only those recored that are in tblInteres
Posted
Updated 28-Nov-16 23:47pm

1 solution

Quote:
Question : you have VisitorID and UserID. then why have you used VisitorAutoID and UserAutoID ?

Solution : Remove join And add Left join. (JOIN tblInterest
SQL
LEFT JOIN tblInterest
)
 
Share this answer
 
v2
Comments
Vikas Hire 29-Nov-16 6:20am    
Thank You... It worked out..
Er. Neel Kamal 29-Nov-16 6:35am    
Nice to know. Enjoy buddy.

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