GROUP BY error :(

This is a discussion on GROUP BY error :( within the MySQL Database forums, part of the Database Forums category; I have 2 tables categories & applications. I am trying to select all the categories and each category count all ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-27-2007
Sutabi
 
Posts: n/a
Default GROUP BY error :(

I have 2 tables categories & applications. I am trying to select all
the categories and each category count all the applications as a
total. The link below has the query I used and the query I tried to
create to accomplish them, but seems to have no luck.

http://dpaste.com/15434/

Reply With Quote
  #2 (permalink)  
Old 07-27-2007
Jerry Stuckle
 
Posts: n/a
Default Re: GROUP BY error :(

Sutabi wrote:
> I have 2 tables categories & applications. I am trying to select all
> the categories and each category count all the applications as a
> total. The link below has the query I used and the query I tried to
> create to accomplish them, but seems to have no luck.
>
> http://dpaste.com/15434/
>


First of all, you should put your query, expected result, etc. in the
message, not refer to a web page. What happens if next week someone has
a similar problem? Your web page will be gone, but your question won't.

For the record, the info is:

QUERY:
=================================================
SELECT c.*, COUNT(DISTINCT a.app_id) AS app_total
FROM categories AS c, applications AS a
WHERE (a.cat_id = c.cat_id)
GROUP BY a.app_id


RESULT:
====================================
cat_id |cat_name | app_total
------------------------------------
1 |News | 1
1 |News | 1

What I was hoping to get:
====================================
cat_id |cat_name | app_total
------------------------------------
1 |News | 2

So I revamped the query to group by `app_total`, but guess what I CANT!!

QUERY:
=================================================
SELECT c.*, COUNT(DISTINCT a.app_id) AS app_total
FROM categories AS c, applications AS a
WHERE (a.cat_id = c.cat_id)
GROUP BY app_total

Error:
=================================================
#1056 - Can't group on 'app_total'


You don't want to group by app_total, because this would group
everything with "1" for a total together, no matter what the cat_id is.

Now - what happens if you GROUP BY c.cat_id?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 05:34 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0