PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > query with COUNT (what am I doing wrong?)
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
query with COUNT (what am I doing wrong?)

Réponse
 
LinkBack Outils de la discussion
Vieux 25/10/2007, 13h00   #1
panchettone
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut query with COUNT (what am I doing wrong?)


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!
  Réponse avec citation
Vieux 25/10/2007, 13h08   #2
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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

  Réponse avec citation
Vieux 25/10/2007, 13h27   #3
panchettone
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: query with COUNT (what am I doing wrong?)


>
> 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
>





a new error:
[
#1140 - Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP
columns is illegal if there is no GROUP BY clause
]
  Réponse avec citation
Vieux 25/10/2007, 14h25   #4
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: query with COUNT (what am I doing wrong?)

On 25 Oct, 12:27, panchettone <pan_che_ttone@non_morde.bau> wrote:
> > 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

>
> a new error:
> [
> #1140 - Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP
> columns is illegal if there is no GROUP BY clause
> ]


Well that's basic GROUP BY syntax!

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
GROUP BY v.title, v.desc, v.cat, u.username, t.team_name

  Réponse avec citation
Vieux 25/10/2007, 15h12   #5
panchettone
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: query with COUNT (what am I doing wrong?)

Captain Paralytic ha scritto:

>
> Well that's basic GROUP BY syntax!




well, the fact is I don't need any group by
  Réponse avec citation
Vieux 25/10/2007, 15h24   #6
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: query with COUNT (what am I doing wrong?)

On 25 Oct, 14:12, panchettone <pan_che_ttone@non_morde.bau> wrote:
> Captain Paralytic ha scritto:
>
>
>
> > Well that's basic GROUP BY syntax!

>
> well, the fact is I don't need any group by


OH, well you had better argue that out with MySQL because it says you
do!

If you are not happy with the syntax supplied by the MySQL product and
SQL, you had better write your own RDBMS and your own SQL standard!

  Réponse avec citation
Vieux 25/10/2007, 15h41   #7
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: query with COUNT (what am I doing wrong?)

Captain Paralytic wrote:
> On 25 Oct, 14:12, panchettone <pan_che_ttone@non_morde.bau> wrote:
>> Captain Paralytic ha scritto:
>>
>>
>>
>>> Well that's basic GROUP BY syntax!

>> well, the fact is I don't need any group by

>
> OH, well you had better argue that out with MySQL because it says you
> do!
>
> If you are not happy with the syntax supplied by the MySQL product and
> SQL, you had better write your own RDBMS and your own SQL standard!
>
>


It's more than just MySQL, Paul. That's part of the SQL standard. In
fact, MySQL has historically been much more lenient than other databases.

IIRC, the SQL standard requires that when you mix aggregate functions
with columns (or non-aggregate functions) you must GROUP BY all
non-aggregate columns or functions. MySQL hasn't enforced it that much
in the past.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  Réponse avec citation
Vieux 25/10/2007, 16h07   #8
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: query with COUNT (what am I doing wrong?)

On 25 Oct, 14:41, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> Captain Paralytic wrote:
> > On 25 Oct, 14:12, panchettone <pan_che_ttone@non_morde.bau> wrote:
> >> Captain Paralytic ha scritto:

>
> >>> Well that's basic GROUP BY syntax!
> >> well, the fact is I don't need any group by

>
> > OH, well you had better argue that out with MySQL because it says you
> > do!

>
> > If you are not happy with the syntax supplied by the MySQL product and
> > SQL, you had better write your own RDBMS and your own SQL standard!

>
> It's more than just MySQL, Paul. That's part of the SQL standard.


Errm, hence why I said "you had better write your own RDBMS and your
own SQL standard!"

  Réponse avec citation
Vieux 25/10/2007, 16h07   #9
panchettone
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: query with COUNT (what am I doing wrong?)


>
> OH, well you had better argue that out with MySQL because it says you
> do!
>
> If you are not happy with the syntax supplied by the MySQL product and
> SQL, you had better write your own RDBMS and your own SQL standard!
>




ok, I didn't want to start a fight, sorry for saying what I said, it was
my ignorance speaking for me. I was just wondering -since my query is
just working- if that group-by is something that can alter the way the
results are sorted by (the entire query I did not post ends with an
order by desc)
  Réponse avec citation
Vieux 25/10/2007, 16h18   #10
panchettone
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: query with COUNT (what am I doing wrong?)



> IIRC, the SQL standard requires that when you mix aggregate functions
> with columns (or non-aggregate functions) you must GROUP BY all
> non-aggregate columns or functions.




could you suggest a place online where I can find tips like this one?
  Réponse avec citation
Vieux 25/10/2007, 16h28   #11
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: query with COUNT (what am I doing wrong?)

On 25 Oct, 15:18, panchettone <pan_che_ttone@non_morde.bau> wrote:
> > IIRC, the SQL standard requires that when you mix aggregate functions
> > with columns (or non-aggregate functions) you must GROUP BY all
> > non-aggregate columns or functions.

>
> could you suggest a place online where I can find tips like this one?


The Reference Manual!

http://dev.mysql.com/doc/refman/5.0/en/

  Réponse avec citation
Vieux 25/10/2007, 16h29   #12
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: query with COUNT (what am I doing wrong?)

On 25 Oct, 15:07, panchettone <pan_che_ttone@non_morde.bau> wrote:
> > OH, well you had better argue that out with MySQL because it says you
> > do!

>
> > If you are not happy with the syntax supplied by the MySQL product and
> > SQL, you had better write your own RDBMS and your own SQL standard!

>
> ok, I didn't want to start a fight, sorry for saying what I said, it was
> my ignorance speaking for me. I was just wondering -since my query is
> just working- if that group-by is something that can alter the way the
> results are sorted by (the entire query I did not post ends with an
> order by desc)


Jerry and I aren't fighting - yet!

  Réponse avec citation
Vieux 26/10/2007, 06h19   #13
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: query with COUNT (what am I doing wrong?)

Captain Paralytic wrote:
> On 25 Oct, 15:07, panchettone <pan_che_ttone@non_morde.bau> wrote:
>>> OH, well you had better argue that out with MySQL because it says you
>>> do!
>>> If you are not happy with the syntax supplied by the MySQL product and
>>> SQL, you had better write your own RDBMS and your own SQL standard!

>> ok, I didn't want to start a fight, sorry for saying what I said, it was
>> my ignorance speaking for me. I was just wondering -since my query is
>> just working- if that group-by is something that can alter the way the
>> results are sorted by (the entire query I did not post ends with an
>> order by desc)

>
> Jerry and I aren't fighting - yet!
>
>


Aw, come on, Paul, put up your dukes! :-)

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  Réponse avec citation
Vieux 26/10/2007, 10h24   #14
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: query with COUNT (what am I doing wrong?)

On 26 Oct, 05:19, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> Captain Paralytic wrote:
> > On 25 Oct, 15:07, panchettone <pan_che_ttone@non_morde.bau> wrote:
> >>> OH, well you had better argue that out with MySQL because it says you
> >>> do!
> >>> If you are not happy with the syntax supplied by the MySQL product and
> >>> SQL, you had better write your own RDBMS and your own SQL standard!
> >> ok, I didn't want to start a fight, sorry for saying what I said, it was
> >> my ignorance speaking for me. I was just wondering -since my query is
> >> just working- if that group-by is something that can alter the way the
> >> results are sorted by (the entire query I did not post ends with an
> >> order by desc)

>
> > Jerry and I aren't fighting - yet!

>
> Aw, come on, Paul, put up your dukes! :-)
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================


Yeah, you wanna come outside (of usenet) and say that }-()

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 00h46.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,17022 seconds with 22 queries