View Single Post

  #2 (permalink)  
Old 10-25-2007
Captain Paralytic
 
Posts: n/a
Default Re: query with COUNT (what am I doing wrong?)

On 25 Oct, 12:00, panchettone <pan_che_ttone@non_morde.bau> wrote:
> Hi, I'm trying to run this query:
>
> --->SELECT COUNT(v.id) as C, v.title, v.desc, v.cat, u.username, t.team_name
> FROM videos AS v
> INNER JOIN users AS u ON v.user_id = u.user_id
> INNER JOIN team_members tm ON tm.user_id = u.user_id
> INNER JOIN teams AS t ON tm.team_id = t.team_id
>
> but I get an error
> [
> #1064 - You have an error in your SQL syntax; check the manual that
> corresponds to your MySQL server version for the right syntax to use
> near '.title, v.desc' at line 1
> ]
>
> If I omit COUNT (but I need it...), it perfectly works.
> What am I doing wrong? How could I rewrite my query? Thanks!


Try:

SELECT COUNT(v.id) cnt, v.title, v.desc, v.cat, u.username,
t.team_name
FROM videos AS v
INNER JOIN users AS u ON v.user_id = u.user_id
INNER JOIN team_members tm ON tm.user_id = u.user_id
INNER JOIN teams AS t ON tm.team_id = t.team_id

Reply With Quote