Your whole query is malformed. You have an aggregate function in the having.

try:
select  f1,max(f2) from tt where f1=1 group by f1;

Gabriel Tataranu wrote:

Hi,

this is NOT correct behavior. Where clause returns (1,1) and (1,2). The HAVING clause should be applied to what WHERE has selected and choose the (1,2) record.
A quote from the manual "It (HAVING) is applied last, just before items are sent to the client, with no optimisation". This is obviously not the case here. It looks like HAVING and WHERE are both appliend to the source record set.


Regards,

Gabriel



This is correct.
WHERE clause returns (1,1)
HAVING eliminates all records not HAVING f2=3.

[EMAIL PROTECTED] wrote:


Description:


        HAVING in SELECT is evaluated before WHERE. This is not the
correct behaviour as HAVING should deal with the remainder of the WHERE
selection (according to manual)



How-To-Repeat:


mysql: create table tt (f1 int, f2 int);
Query OK, 0 rows affected (0.01 sec)

mysql: insert into tt values(1,1);
Query OK, 1 row affected (0.01 sec)

mysql: insert into tt values(1,2);
Query OK, 1 row affected (0.00 sec)

mysql: insert into tt values(2,3);
Query OK, 1 row affected (0.00 sec)

mysql: select * from tt where f1=1 having f2=max(f2);
Empty set (0.00 sec)




---------------------------------------------------------------------
Before posting, please check:
  http://www.mysql.com/manual.php   (the manual)
  http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php







--------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php



Reply via email to