Connecting Tech Pros Worldwide Forums | Help | Site Map

must I use 2 queries

Bob Bedford
Guest
 
Posts: n/a
#1: Jul 17 '05
Not having access to any mysql NG, I try to post here:

I've a query where I'd like to get the different values, but also a max for
2 fields:

SELECT max(CounterLogResult) as maxlog, max(CounterClick) as maxclick,
articleid, articlename...

but I get the errro:
Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is
illegal if there is no GROUP BY clause

I don't understand what I've to group....



Alvaro G. Vicario
Guest
 
Posts: n/a
#2: Jul 17 '05

re: must I use 2 queries


*** Bob Bedford escribió/wrote (Mon, 21 Mar 2005 19:55:39 +0100):[color=blue]
> SELECT max(CounterLogResult) as maxlog, max(CounterClick) as maxclick,
> articleid, articlename...
>
> but I get the errro:
> Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is
> illegal if there is no GROUP BY clause[/color]

maxlog and maxclick are escalar values while articleid and articlename are
probably arrays (i.e., more than one row). You cannot mix them. I may be
wrong but you'd need two separate queries.



--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la intemperie)
++ No envíes tu dudas a mi correo, publícalas en el grupo
-+ Do not send me your questions, post them to the group
--
Geoff M
Guest
 
Posts: n/a
#3: Jul 17 '05

re: must I use 2 queries


bedford1@notforspammershotmail.com says...
[color=blue]
> I've a query where I'd like to get the different values, but also a max for
> 2 fields:
>
> SELECT max(CounterLogResult) as maxlog, max(CounterClick) as maxclick,
> articleid, articlename...
>
> but I get the errro:
> Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is
> illegal if there is no GROUP BY clause
>
> I don't understand what I've to group....[/color]

SELECT max(CounterLogResult) as maxlog, max(CounterClick) as maxclick,
articleid, articlename...
GROUP BY articleid, articlename...

Group by all selected columns that are NOT aggregated values.

Geoff M
Bob Bedford
Guest
 
Posts: n/a
#4: Jul 17 '05

re: must I use 2 queries


>> I've a query where I'd like to get the different values, but also a max[color=blue][color=green]
>> for
>> 2 fields:
>>
>> SELECT max(CounterLogResult) as maxlog, max(CounterClick) as maxclick,
>> articleid, articlename...
>>
>> but I get the errro:
>> Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns
>> is
>> illegal if there is no GROUP BY clause
>>
>> I don't understand what I've to group....[/color]
>
> SELECT max(CounterLogResult) as maxlog, max(CounterClick) as maxclick,
> articleid, articlename...
> GROUP BY articleid, articlename...[/color]

Thanks for replying.

About speed consideration: it's is faster to group or to execute 2 queries ?


Geoff Muldoon
Guest
 
Posts: n/a
#5: Jul 17 '05

re: must I use 2 queries


@notforspammershotmail.com says...[color=blue][color=green]
> > SELECT max(CounterLogResult) as maxlog, max(CounterClick) as maxclick,
> > articleid, articlename...
> > GROUP BY articleid, articlename...[/color]
>
> About speed consideration: it's is faster to group or to execute 2 queries ?[/color]

Too many variables (which columns are indexed, etc.) for a definitive
answer, but generally one group by preferred over two queries.

Geoff M
Alvaro G. Vicario
Guest
 
Posts: n/a
#6: Jul 17 '05

re: must I use 2 queries


*** Bob Bedford escribió/wrote (Wed, 23 Mar 2005 08:14:33 +0100):[color=blue]
> About speed consideration: it's is faster to group or to execute 2 queries ?[/color]

The speed of queries mainly depends on complexity and number of returned
rows.

In your case you need two escalar values, there's no need to make data grow
adding this to a full row collection:

x x

+

x x x x x
x x x x x
x x x x x
x x x x x
x x x x x
....

vs.

x x x x x x x
- - x x x x x
- - x x x x x
- - x x x x x
- - x x x x x



--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la intemperie)
++ No envíes tu dudas a mi correo, publícalas en el grupo
-+ Do not send me your questions, post them to the group
--
Closed Thread