Mark Papadakis writes:
 > Hi all,
 > 
 > I was wondering what's wrong with a query like this:
 > 
 > select itemlist.... , sum(field1), count(*) as cnt from table where where conditions 
 >group by id having cnt=2 order by field_x, field_y desc limit 10
 > 
 > I am expecting to get the requested rows order by field_x. Those with same value ( 
 >as in field_x=5 ) should be additionaly ordered by field_y. So for example I 'd get:
 > 
 > field_x, field_y
 > 5        2
 > 5        2
 > 5        1
 > 5        0
 > 4        5
 > 3        8
 > 
 > and so on.
 > 
 > Am I missing the point of order by here? If so, what is the best way/fastest way to 
 >achieve the required results set?
 > 
 > Please, reply directly to me ( [EMAIL PROTECTED] ) if possible.
 > 
 > Thank you,
 > 
 > 
 > 
 > 
 > Mark Papadakis
 > R&D Director - Web Division
 > Phaistos Networks, S.A. - http://www.phaistosnetworks.gr 
 > [EMAIL PROTECTED] T:+30-892-23855  F:+30-892-22670
 > - A DOL Digital Company
 > 
 > 


Hi!

Your problem is quite simple.

Columns not listed in select_list , but used in order by and / or
group by, are silently added to the select_list.

In your case this happens with id field.

This is perfectly in accordance with ANSI SQL standards.


Regards,

Sinisa

      ____  __     _____   _____  ___     ==  MySQL AB
     /*/\*\/\*\   /*/ \*\ /*/ \*\ |*|     Sinisa Milivojevic
    /*/ /*/ /*/   \*\_   |*|   |*||*|     mailto:[EMAIL PROTECTED]
   /*/ /*/ /*/\*\/*/  \*\|*|   |*||*|     Larnaka, Cyprus
  /*/     /*/  /*/\*\_/*/ \*\_/*/ |*|____
  ^^^^^^^^^^^^/*/^^^^^^^^^^^\*\^^^^^^^^^^^
             /*/             \*\                Developers Team

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