Re: Problem with GROUP BY

2008-10-20 Thread Moon's Father
Learnt!

On Wed, Oct 15, 2008 at 5:28 PM, philip [EMAIL PROTECTED] wrote:

  Date: Tue, 14 Oct 2008 16:55:11 +0300
  From: Olexandr Melnyk [EMAIL PROTECTED]
  To: [EMAIL PROTECTED], mysql@lists.mysql.com
  Subject: Re: Problem with GROUP BY
 
  http://jan.kneschke.de/projects/mysql/groupwise-max
 
  2008/10/14 Peter Brawley [EMAIL PROTECTED]
 
   Philip
  
mysql SELECT number, MAX(event), name FROM info GROUP BY number;
  
  
   For discussion  examples see Within-group aggregates at
   http://www.artfulsoftware.com/queries.php.

 Thank you both very much for your replies.

 Of course the solution is 'obvious' now I know the answer but as a
 relative newcomer to MySQL I had spent the best part of a day trying to
 find it.

 TTFN,

   Philip Riebold, [EMAIL PROTECTED]   /\
   Media Services\ /
   University College London  X  ASCII Ribbon Campaign
   Windeyer Building, 46 Cleveland Street/ \ Against HTML Mail
   London, W1T 4JF
   +44 (0)20 7679 9259 (switchboard), 09259 (internal)

 --
 MySQL General Mailing List
 For list archives: http://lists.mysql.com/mysql
 To unsubscribe:
 http://lists.mysql.com/[EMAIL PROTECTED]




-- 
I'm a MySQL DBA in china.
More about me just visit here:
http://yueliangdao0608.cublog.cn


Re: Problem with GROUP BY

2008-10-15 Thread philip
 Date: Tue, 14 Oct 2008 16:55:11 +0300
 From: Olexandr Melnyk [EMAIL PROTECTED]
 To: [EMAIL PROTECTED], mysql@lists.mysql.com
 Subject: Re: Problem with GROUP BY
 
 http://jan.kneschke.de/projects/mysql/groupwise-max
 
 2008/10/14 Peter Brawley [EMAIL PROTECTED]
 
  Philip
 
   mysql SELECT number, MAX(event), name FROM info GROUP BY number;
 
 
  For discussion  examples see Within-group aggregates at
  http://www.artfulsoftware.com/queries.php.

Thank you both very much for your replies. 

Of course the solution is 'obvious' now I know the answer but as a
relative newcomer to MySQL I had spent the best part of a day trying to
find it. 

TTFN,

   Philip Riebold, [EMAIL PROTECTED]   /\
   Media Services\ /
   University College London  X  ASCII Ribbon Campaign
   Windeyer Building, 46 Cleveland Street/ \ Against HTML Mail
   London, W1T 4JF
   +44 (0)20 7679 9259 (switchboard), 09259 (internal)

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: Problem with GROUP BY

2008-10-14 Thread Peter Brawley

Philip


mysql SELECT number, MAX(event), name FROM info GROUP BY number;


For discussion  examples see Within-group aggregates at 
http://www.artfulsoftware.com/queries.php.


PB

-

philip wrote:

I created a table with,

CREATE TABLE info (
number INTEGER UNSIGNED,
event INTEGER UNSIGNED,
name VARCHAR(2000) NOT NULL,
PRIMARY KEY (number, event)
);

and populated it with data to produce this,

++---+---+
| number | event | name  |
++---+---+
| 67 | 1 | Alice |
| 67 | 2 | Bob   |
| 69 | 1 | Carol |
| 70 | 1 | Alex  |
| 71 | 1 | David |
| 72 | 1 | Bob   |
| 72 | 2 | Alice |
| 72 | 3 | David |
++---+---+

What I want to produce is a table with rows from the original with only
the maximum value of event for each corresponding number selected, like
this

+++---+
| number | event  | name  |
+++---+
| 67 |  2 | Bob   |
| 69 |  1 | Carol |
| 70 |  1 | Alex  |
| 71 |  1 | David |
| 72 |  3 | David |
+++---+

The closest I have managed to produce using GROUP BY is,

mysql SELECT number, MAX(event), name FROM info GROUP BY number;
+++---+
| number | MAX(event) | name  |
+++---+
| 67 |  2 | Alice | - should be Bob
| 69 |  1 | Carol |
| 70 |  1 | Alex  |
| 71 |  1 | David |
| 72 |  3 | Bob   | - should be David
+++---+

I tried using a HAVING clause but got nowhere.

Can anybody help please ?

TTFN,

   Philip Riebold, [EMAIL PROTECTED]   /\
   Media Services\ /
   University College London  X  ASCII Ribbon Campaign
   Windeyer Building, 46 Cleveland Street/ \ Against HTML Mail
   London, W1T 4JF
   +44 (0)20 7679 9259 (switchboard), 09259 (internal)


  




Internal Virus Database is out of date.
Checked by AVG - http://www.avg.com 
Version: 8.0.173 / Virus Database: 270.7.6/1713 - Release Date: 10/7/2008 6:40 PM


  


Re: Problem with GROUP BY

2008-10-14 Thread Olexandr Melnyk
http://jan.kneschke.de/projects/mysql/groupwise-max

2008/10/14 Peter Brawley [EMAIL PROTECTED]

 Philip

  mysql SELECT number, MAX(event), name FROM info GROUP BY number;


 For discussion  examples see Within-group aggregates at
 http://www.artfulsoftware.com/queries.php.

 PB

 -

 philip wrote:

 I created a table with,

 CREATE TABLE info (
number INTEGER UNSIGNED,
event INTEGER UNSIGNED,
name VARCHAR(2000) NOT NULL,
PRIMARY KEY (number, event)
 );

 and populated it with data to produce this,

 ++---+---+
 | number | event | name  |
 ++---+---+
 | 67 | 1 | Alice |
 | 67 | 2 | Bob   |
 | 69 | 1 | Carol |
 | 70 | 1 | Alex  |
 | 71 | 1 | David |
 | 72 | 1 | Bob   |
 | 72 | 2 | Alice |
 | 72 | 3 | David |
 ++---+---+

 What I want to produce is a table with rows from the original with only
 the maximum value of event for each corresponding number selected, like
 this

 +++---+
 | number | event  | name  |
 +++---+
 | 67 |  2 | Bob   |
 | 69 |  1 | Carol |
 | 70 |  1 | Alex  |
 | 71 |  1 | David |
 | 72 |  3 | David |
 +++---+

 The closest I have managed to produce using GROUP BY is,

 mysql SELECT number, MAX(event), name FROM info GROUP BY number;
 +++---+
 | number | MAX(event) | name  |
 +++---+
 | 67 |  2 | Alice | - should be Bob
 | 69 |  1 | Carol |
 | 70 |  1 | Alex  |
 | 71 |  1 | David |
 | 72 |  3 | Bob   | - should be David
 +++---+

 I tried using a HAVING clause but got nowhere.

 Can anybody help please ?

 TTFN,

   Philip Riebold, [EMAIL PROTECTED]   /\
   Media Services\ /
   University College London  X  ASCII Ribbon Campaign
   Windeyer Building, 46 Cleveland Street/ \ Against HTML Mail
   London, W1T 4JF
   +44 (0)20 7679 9259 (switchboard), 09259 (internal)


  


 Internal Virus Database is out of date.
 Checked by AVG - http://www.avg.com Version: 8.0.173 / Virus Database:
 270.7.6/1713 - Release Date: 10/7/2008 6:40 PM






-- 
--
Sincerely yours,
Olexandr Melnyk
http://omelnyk.net/


Problem with GROUP BY

2008-10-14 Thread philip
I created a table with,

CREATE TABLE info (
number INTEGER UNSIGNED,
event INTEGER UNSIGNED,
name VARCHAR(2000) NOT NULL,
PRIMARY KEY (number, event)
);

and populated it with data to produce this,

++---+---+
| number | event | name  |
++---+---+
| 67 | 1 | Alice |
| 67 | 2 | Bob   |
| 69 | 1 | Carol |
| 70 | 1 | Alex  |
| 71 | 1 | David |
| 72 | 1 | Bob   |
| 72 | 2 | Alice |
| 72 | 3 | David |
++---+---+

What I want to produce is a table with rows from the original with only
the maximum value of event for each corresponding number selected, like
this

+++---+
| number | event  | name  |
+++---+
| 67 |  2 | Bob   |
| 69 |  1 | Carol |
| 70 |  1 | Alex  |
| 71 |  1 | David |
| 72 |  3 | David |
+++---+

The closest I have managed to produce using GROUP BY is,

mysql SELECT number, MAX(event), name FROM info GROUP BY number;
+++---+
| number | MAX(event) | name  |
+++---+
| 67 |  2 | Alice | - should be Bob
| 69 |  1 | Carol |
| 70 |  1 | Alex  |
| 71 |  1 | David |
| 72 |  3 | Bob   | - should be David
+++---+

I tried using a HAVING clause but got nowhere.

Can anybody help please ?

TTFN,

   Philip Riebold, [EMAIL PROTECTED]   /\
   Media Services\ /
   University College London  X  ASCII Ribbon Campaign
   Windeyer Building, 46 Cleveland Street/ \ Against HTML Mail
   London, W1T 4JF
   +44 (0)20 7679 9259 (switchboard), 09259 (internal)


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: query problem with GROUP BY and ORDER BY

2002-06-02 Thread Philip Spradling

On Sat, 01 Jun 2002 11:58:38 +0200
Claire Forchheimer [EMAIL PROTECTED] wrote:

I know the answer to the first part at least.  I think you want to use two columns in 
the order by clause, and leave out the group by clause.  As in:

select * from tbl order by apt, name;

I'm afraid its too late at night for me to be able to think about the rest.  I'm sure 
it can be done though.

Philip


 Hi all,
 
 I have a table including two colums: names and apartment numbers:
 
 apt #| name
 --
 1 | Smith Joe
 1 | Smith Anne
 2 | Doe Richard
 3 | Svensen Mike
 3 | Brant Liza
 
 I need to get a list in alphabetical order, but with people in the same
 apt keept together:
 
 Brant, Svensen
 Doe
 Smith, Smith
 
 The difficulty is to get people living in the same apt grouped together.
 
 SELECT * FROM tbl GROUP BY apt ORDER BY name  - will drop the second
 name
 found in each apt!
 
 (The result would be this list:
 Brant
 Doe
 Smith)
 
 I've been banging my head black and blue over this query! Can anyone
 help??!?
 
 
 Two more issues in addition to this query is:
 
 I'm using a PHP statement to find only the lastname in the name field,
 can
 this be done already in the query??
 
 A nice feature would be to only list one name if both lastnames are the
 same in one apt. In other words the list would then look like:
 
 Brant, Svensen
 Doe
 Smith
 
 can  this be done???


-- 
Philip Spradling
Unemployed C/C++/Java/SQL programmer
(Who do you know who could use an experienced, talented but overeducated programmer?)
[EMAIL PROTECTED]  
http:[EMAIL PROTECTED]/

-
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




query problem with GROUP BY and ORDER BY

2002-06-01 Thread Claire Forchheimer

Hi all,

I have a table including two colums: names and apartment numbers:

apt #| name
--
1 | Smith Joe
1 | Smith Anne
2 | Doe Richard
3 | Svensen Mike
3 | Brant Liza

I need to get a list in alphabetical order, but with people in the same
apt keept together:

Brant, Svensen
Doe
Smith, Smith

The difficulty is to get people living in the same apt grouped together.

SELECT * FROM tbl GROUP BY apt ORDER BY name  - will drop the second
name
found in each apt!

(The result would be this list:
Brant
Doe
Smith)

I've been banging my head black and blue over this query! Can anyone
help??!?


Two more issues in addition to this query is:

I'm using a PHP statement to find only the lastname in the name field,
can
this be done already in the query??

A nice feature would be to only list one name if both lastnames are the
same in one apt. In other words the list would then look like:

Brant, Svensen
Doe
Smith

can  this be done???





-
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




urgent : Problem in Group by clause

2002-02-16 Thread SankaraNarayanan Mahadevan

hi all,

i have a problem in mysql query...
lemme state the scenario...

i have a table 'UploadDetails' in which i am storing
data regd files...

the fields are:
FileName, Title, Designer, UploadedBy, SubmittedDate

i want to get details about whose files are designed
by who..etc...
that is i need to use group by in select statement..

i want to display the details in the web page ...

say there are 3 records as below against each field:
1. 'a.jpg','test','david','john','2002-02-14'
2. 'b.bmp','bmp file','richard','mary','2002-02-14'
3. 'c.htm','web','david','mary','2002-02-15'


now i want to display the details grouped by Designer
(the third field).

when i use the following query:

select
FileName,Title,Designer,UploadedBy,SubmittedDate
From UploadDetails
Group By Designer

i get only one row...

why?

can anyone solve this problem...

thanks in advance

Shankar

__
Do You Yahoo!?
Yahoo! Sports - Coverage of the 2002 Olympic Games
http://sports.yahoo.com

-
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




urgent : Problem in Group by clause

2002-02-16 Thread SankaraNarayanan Mahadevan

hi all,

i have a problem in mysql query...
lemme state the scenario...

i have a table 'UploadDetails' in which i am storing
data regd files...

the fields are:
FileName, Title, Designer, UploadedBy, SubmittedDate

i want to get details about whose files are designed
by who..etc...
that is i need to use group by in select statement..

i want to display the details in the web page ...

say there are 3 records as below against each field:
1. 'a.jpg','test','david','john','2002-02-14'
2. 'b.bmp','bmp file','richard','mary','2002-02-14'
3. 'c.htm','web','david','mary','2002-02-15'


now i want to display the details grouped by Designer
(the third field).

when i use the following query:

select
FileName,Title,Designer,UploadedBy,SubmittedDate
From UploadDetails
Group By Designer

i get only one row...

why?

can anyone solve this problem...

thanks in advance

Shankar

__
Do You Yahoo!?
Yahoo! Sports - Coverage of the 2002 Olympic Games
http://sports.yahoo.com

-
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




Re: urgent : Problem in Group by clause

2002-02-16 Thread Teri Salisbury

Hi Shankar,

This is your old buddy Scott S.

Try order by rather than group byThis will get you what you are looking
for

Scott Salisbury

- Original Message -
From: SankaraNarayanan Mahadevan [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Saturday, February 16, 2002 3:42 PM
Subject: urgent : Problem in Group by clause


hi all,

i have a problem in mysql query...
lemme state the scenario...

i have a table 'UploadDetails' in which i am storing
data regd files...

the fields are:
FileName, Title, Designer, UploadedBy, SubmittedDate

i want to get details about whose files are designed
by who..etc...
that is i need to use group by in select statement..

i want to display the details in the web page ...

say there are 3 records as below against each field:
1. 'a.jpg','test','david','john','2002-02-14'
2. 'b.bmp','bmp file','richard','mary','2002-02-14'
3. 'c.htm','web','david','mary','2002-02-15'


now i want to display the details grouped by Designer
(the third field).

when i use the following query:

select
FileName,Title,Designer,UploadedBy,SubmittedDate
From UploadDetails
Group By Designer

i get only one row...

why?

can anyone solve this problem...

thanks in advance

Shankar

__
Do You Yahoo!?
Yahoo! Sports - Coverage of the 2002 Olympic Games
http://sports.yahoo.com

-
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




Re: Re: Problem with GROUP BY ... DESC

2001-12-10 Thread Michael Widenius


 Arjen == Arjen G Lentz [EMAIL PROTECTED] writes:

Arjen Hi,
Arjen - Original Message -
Arjen From: AJ [EMAIL PROTECTED]


   Ver 11.15 Distrib 3.23.46, for pc-linux-gnu (i686)
   The problem that has cropped up I have is that in all GROUP BY column
   DESC
   statements, the DESC is now not being recognized, and the query is being
   returned in ascending order.  If I use ORDER BY... DESC that works fine.

 I'm seeing the same bug on 3.23.45 (and maybe others but I can't remember
 all the versions I've played with recently).  It does the same thing where
 it accepts the syntax but does not respect it (and returns rows in the
 default ASC ordering).
 
 The problem is apparently solved if you kluge with e.g.
 select field, count(field) from table group by field order by field
 desc but it IS a kluge.

This is now fixed in the MySQL 3.23.47 and MySQL 4.0.1 source trees.

Here is a patch for this:

= sql/sql_lex.h 1.34 vs edited =
*** /tmp/sql_lex.h-1.34-29757   Sun Oct  7 14:18:08 2001
--- edited/sql/sql_lex.hMon Dec 10 17:27:02 2001
***
*** 140,146 
enum lex_states next_state;
enum enum_duplicates duplicates;
enum enum_tx_isolation tx_isolation;
!   uint in_sum_expr,grant,grant_tot_col,which_columns, sort_default;
thr_lock_type lock_option;
boolcreate_refs,drop_primary,drop_if_exists,local_file;
bool  in_comment,ignore_space,verbose;
--- 140,146 
enum lex_states next_state;
enum enum_duplicates duplicates;
enum enum_tx_isolation tx_isolation;
!   uint in_sum_expr,grant,grant_tot_col,which_columns;
thr_lock_type lock_option;
boolcreate_refs,drop_primary,drop_if_exists,local_file;
bool  in_comment,ignore_space,verbose;
= sql/sql_yacc.yy 1.86 vs edited =
*** /tmp/sql_yacc.yy-1.86-29757 Tue Aug 21 20:06:00 2001
--- edited/sql/sql_yacc.yy  Mon Dec 10 17:26:37 2001
***
*** 470,476 
ULONGLONG_NUM
  
  %type item
!   literal text_literal insert_ident group_ident order_ident
simple_ident select_item2 expr opt_expr opt_else sum_expr in_sum_expr
table_wild opt_pad no_in_expr expr_expr simple_expr no_and_expr
using_list
--- 470,476 
ULONGLONG_NUM
  
  %type item
!   literal text_literal insert_ident order_ident
simple_ident select_item2 expr opt_expr opt_else sum_expr in_sum_expr
table_wild opt_pad no_in_expr expr_expr simple_expr no_and_expr
using_list
***
*** 1869,1878 
| GROUP BY group_list
  
  group_list:
!   group_list ',' group_ident
! { if (add_group_to_list($3,(bool) 1)) YYABORT; }
!   | group_ident
! { if (add_group_to_list($1,(bool) 1)) YYABORT; }
  
  /*
  ** Order by statement in select
--- 1869,1878 
| GROUP BY group_list
  
  group_list:
!   group_list ',' order_ident order_dir
! { if (add_group_to_list($3,(bool) $4)) YYABORT; }
!   | order_ident order_dir
! { if (add_group_to_list($1,(bool) $2)) YYABORT; }
  
  /*
  ** Order by statement in select
***
*** 1883,1889 
| order_clause
  
  order_clause:
!   ORDER_SYM BY { Lex-sort_default=1; } order_list
  
  order_list:
order_list ',' order_ident order_dir
--- 1883,1889 
| order_clause
  
  order_clause:
!   ORDER_SYM BY order_list
  
  order_list:
order_list ',' order_ident order_dir
***
*** 1893,1900 
  
  order_dir:
/* empty */ { $$ =  1; }
!   | ASC  { $$ = Lex-sort_default=1; }
!   | DESC { $$ = Lex-sort_default=0; }
  
  
  limit_clause:
--- 1893,1900 
  
  order_dir:
/* empty */ { $$ =  1; }
!   | ASC  { $$ =1; }
!   | DESC { $$ =0; }
  
  
  limit_clause:
***
*** 2451,2459 
ident '.' '*' { $$ = new Item_field(NullS,$1.str,*); }
| ident '.' ident '.' '*'
{ $$ = new Item_field((current_thd-client_capabilities  CLIENT_NO_SCHEMA ? 
NullS : $1.str),$3.str,*); }
- 
- group_ident:
-   order_ident order_dir
  
  order_ident:
expr { $$=$1; }
--- 2451,2456 


Regards,
Monty

-
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




Problem with GROUP BY ... DESC

2001-12-04 Thread AJ

Hello:

I'm new to the list and have a question.  I upgraded from version 3.22 to 
this version:

Ver 11.15 Distrib 3.23.46, for pc-linux-gnu (i686)

The problem that has cropped up I have is that in all GROUP BY column DESC 
statements, the DESC is now not being recognized, and the query is being 
returned in ascending order.  If I use ORDER BY... DESC that works fine.

For example, I have a database with about 25,000 records, and I get these 
results:

WORKING CORRECTLY.

select memberno from testpubl order by memberno desc limit 7

(0,0): 7395261 |
(1,0): 7395260 |
(2,0): 7395259 |
(3,0): 7395258 |
(4,0): 7395257 |
(5,0): 7395256 |
(6,0): 7395255 |

NOT WORKING...

select memberno from testpubl group by memberno desc limit 7

(0,0): 24754 |
(1,0): 24755 |
(2,0): 24805 |
(3,0): 24818 |
(4,0): 24853 |
(5,0): 24882 |
(6,0): 24961 |

(I know that in this example I could just use the ORDER BY statement, but I 
wanted to show what was going on.  I have other queries with COUNT() 
statements in them that need the GROUP BY statement and are having problems.)

It's hopefully implicit here that all these statements were working fine 
before the upgrade.  Any comments would be greatly appreciated.

AJ


-
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




Re: Problem with GROUP BY ... DESC

2001-12-04 Thread Dave Rolsky

On Tue, 4 Dec 2001, AJ wrote:

 Ver 11.15 Distrib 3.23.46, for pc-linux-gnu (i686)

 The problem that has cropped up I have is that in all GROUP BY column DESC
 statements, the DESC is now not being recognized, and the query is being
 returned in ascending order.  If I use ORDER BY... DESC that works fine.

I'm seeing the same bug on 3.23.45 (and maybe others but I can't remember
all the versions I've played with recently).  It does the same thing where
it accepts the syntax but does not respect it (and returns rows in the
default ASC ordering).


-dave

/*==
www.urth.org
We await the New Sun
==*/


-
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




Fwd: Re: Problem with GROUP BY ... DESC

2001-12-04 Thread AJ


  Ver 11.15 Distrib 3.23.46, for pc-linux-gnu (i686)
 
  The problem that has cropped up I have is that in all GROUP BY column DESC
  statements, the DESC is now not being recognized, and the query is being
  returned in ascending order.  If I use ORDER BY... DESC that works fine.

I'm seeing the same bug on 3.23.45 (and maybe others but I can't remember
all the versions I've played with recently).  It does the same thing where
it accepts the syntax but does not respect it (and returns rows in the
default ASC ordering).

The problem is apparently solved if you kluge with e.g.

 select field, count(field) from table group by field order by 
field desc

but it IS a kluge.

AJ 


-
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




Re: Re: Problem with GROUP BY ... DESC

2001-12-04 Thread Arjen G. Lentz

Hi,

- Original Message -
From: AJ [EMAIL PROTECTED]


   Ver 11.15 Distrib 3.23.46, for pc-linux-gnu (i686)
   The problem that has cropped up I have is that in all GROUP BY column
DESC
   statements, the DESC is now not being recognized, and the query is being
   returned in ascending order.  If I use ORDER BY... DESC that works fine.
 I'm seeing the same bug on 3.23.45 (and maybe others but I can't remember
 all the versions I've played with recently).  It does the same thing where
 it accepts the syntax but does not respect it (and returns rows in the
 default ASC ordering).

 The problem is apparently solved if you kluge with e.g.
  select field, count(field) from table group by field order by field
desc
 but it IS a kluge.

That wouldn't not be a kludge actually, since the SQL-99 standard does not
allow ASC/DESC on GROUP BY at all.
It is an extention in the MySQL server (see
http://www.mysql.com/doc/S/E/SELECT.html), and basically it is a shortcut for
exactly what you describe: an ORDER BY with the same fields as the earlier
GROUP BY.

I tried it too on a 3.23, and indeed it does appear to not be working.
Contrary to what is described above though, there is no ordering at all in my
output, not ascending either. So basically it is as you would expect it to be
without any ORDER BY operation. Maybe the output others got was just sheer
luck, as it depends on the order the server reads the data rows

Anyway, I've sent a note to the developers about this, including a sample
reproducing it.


Regards,
Arjen.

--
MySQL Training Worldwide, http://www.mysql.com/training/
   __  ___ ___   __
  /  |/  /_ __/ __/ __ \/ /Mr. Arjen G. Lentz [EMAIL PROTECTED]
 / /|_/ / // /\ \/ /_/ / /__   MySQL AB, Technical Writer, Trainer
/_/  /_/\_, /___/\___\_\___/   Brisbane, QLD Australia
   ___/   www.mysql.com




-
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