Sagewire Logo

query with COUNT (what am I doing wrong?)

14 Message(s) by 3 Author(s) originally posted in mysql discussion


From: panchettone Date:   Thursday, October 25, 2007
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've 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!


From: Captain Paralytic Date:   Thursday, October 25, 2007
wrote in message:
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've 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


From: panchettone Date:   Thursday, October 25, 2007
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
]


From: Captain Paralytic Date:   Thursday, October 25, 2007
wrote in message:
> 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


From: panchettone Date:   Thursday, October 25, 2007
Captain Paralytic ha scritto:

Well that's basic GROUP BY syntax!


well, the fact is I do not need any group by


From: Captain Paralytic Date:   Thursday, October 25, 2007
wrote in message:
Captain Paralytic ha scritto:
> Well that's basic GROUP BY syntax!
well, the fact is I do not need any group by



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

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


From: Jerry Stuckle Date:   Thursday, October 25, 2007
wrote in message:
wrote in message:
Captain Paralytic ha scritto:



Well that's basic GROUP BY syntax!
well, the fact is I do not need any group by
OH, well you had better argue that out with MySQL because it says you
do!
If you aren't 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 has not enforced it that much
in the past.

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


From: Captain Paralytic Date:   Thursday, October 25, 2007
wrote in message:
wrote in message:
wrote in message:
Captain Paralytic ha scritto:
> Well that's basic GROUP BY syntax!
well, the fact is I do not need any group by
> OH, well you had better argue that out with MySQL because it says you
> do!
> If you aren't 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!"


From: panchettone Date:   Thursday, October 25, 2007
OH, well you had better argue that out with MySQL because it says you
do!
If you aren't 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 did not 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 didn't post ends with an
order by desc)


From: panchettone Date:   Thursday, October 25, 2007
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?


From: Captain Paralytic Date:   Thursday, October 25, 2007
wrote in message:
> 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/


From: Captain Paralytic Date:   Thursday, October 25, 2007
wrote in message:
> OH, well you had better argue that out with MySQL because it says you
> do!
> If you aren't 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 did not 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 didn't post ends with an
order by desc)



Jerry and I are not fighting - yet!


From: Jerry Stuckle Date:   Friday, October 26, 2007
wrote in message:
wrote in message:
OH, well you had better argue that out with MySQL because it says you
do!
If you aren't 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 did not 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 didn't post ends with an
order by desc)
Jerry and I are not fighting - yet!


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

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


From: Captain Paralytic Date:   Friday, October 26, 2007
wrote in message:
wrote in message:
wrote in message:
> OH, well you had better argue that out with MySQL because it says you
> do!
> If you aren't 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 did not 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 didn't post ends with an
order by desc)
> Jerry and I are not fighting - yet!
Aw, come on, Paul, put up your dukes! :-)
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@xxxxxxxxxxx
==================



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



Next Message: MySql server in my shareware application


Blogs related to query with COUNT (what am I doing wrong?)

http://bugs.mysql.com/bug.php'id=12744
I am doing this from Ruby, but does not seem to be a Ruby-specific issue. Any ideas' Danielss89 : hi, i get this error when trying to insert something into a table: Column count doesn't match value count at row 1 Danielss89 : i have no ...

can anyone help me get mysql server installed on Ubuntu dapper Ive ...
gar punctuation, have ya heard of it ? Isotopp, join ##php and ask in there instead. wrong nick. my english is not really good. oh sorry, gar join ##php not Isotopp. thats a mysql query or not i was thinking this was the good channel ...

Im developing a PHP web application and I have a query like this ...
and btw… what's "key distribution" in MySQL? hello i am currently doing a query like SELECT *,count(id),MAX(id) FROM channelpollvote WHERE channelpollid=2 GROUP BY vote; but is it possible for MAX to show the max results for the WHOLE ...

GRANT ALL PRIVILEGES ON hlstatsx* TO gameserver@reset4 IDENTIFIED ...
Can someone take a look at a query of mine and tell me why it takes so long to run (if it doesn't freeze my server) ? I'm sure I'm doing something wrong, I've never really used JOIN before and don't understand them that well. does mysql ...

Is there some way to tell mysql to not cache certain tables I have ...
what am I doing wrong here? select customers.first_name, count(invoices.*) from customers left join invoices on invoices.customer_id = customers.id group by customers.id;. depends on the error msg let me ask my crystal ball ...

i am ecommerce creating a custom Google map which has a method ...
PHP makes it very easy to query MySQL [and other databases]. yeah I understand what you mean by reusable functions I even used postgresql. I don’t currently have any ads, sorry. hi, i have seen some websites have thumbnails, ...


Programming | Sports | Autos

copyright 2006
Valid XHTML 1.0 Transitional