serdar
serdar

Reputation: 454

SQL COUNT AS XXX

I am trying to select user followers.As

SELECT     
profil_id, 
profil_user_id, 
profil_fullname, 
profil_puan, 
profil_aciklama, 
UserId,
UserName
COUNT(select follower_id  from follow where followed_id='2') as follower

FROM         
profil ,aspnet_Users
WHERE
profil_user_id ='2' and
profil.profil_user_id=aspnet_Users.UserID

I want to select followers count but its not working.Error :*Incorrect syntax near the keyword 'as'. * where is the problem ? (ı DONT WANT TO USE LEFT JOIN IT HAS ISSUE)

Upvotes: 0

Views: 2147

Answers (2)

Claudio Redi
Claudio Redi

Reputation: 68400

You missed a , after UserName

UserName // <-- missed ',' here
COUNT(select follower_id  from follow where followed_id='2') as follower

Also, this is not valid a valid sql server query

COUNT(select follower_id  from follow where followed_id='2') as follower

A valid option would be following Danila´s code

Upvotes: 3

Danila Polevshchikov
Danila Polevshchikov

Reputation: 2278

Replace

COUNT(select follower_id  from follow where followed_id='2') as follower

with

(select COUNT(follower_id)  from follow where followed_id='2') as follower

Upvotes: 3

Related Questions