Problem using Max()

This is a discussion on "Problem using Max()" within the Databases section. This forum, and the thread "Problem using Max() are both part of the Program Your Website category.



 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > Databases

Notices


Reply
 
LinkBack Thread Tools
  #1  
Old May 5th, 2007, 07:45
Junior Member
Join Date: Apr 2007
Location: India
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Problem using Max()

I have a table activity with following fields

Table:activity

activity_id proof_pages chapter_id
-------------- ---------------- --------------
1 23 10
2 32 10
3 10 15

now i need to get the max(proof_pages) and the corresponding activity_id.

i used the following query:

select activity_id,max(proof_pages) from activity
where chapter_id='10'
group by chapter_id

Output:
-------
activity_id = 1
max(proof_pages)=32

but the actual result should be
activity_id=2
max(proof_pages)=32

how should i modify the query?
Thanks,
Thanuja
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old May 6th, 2007, 11:34
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Problem using Max()

Why are you using the group clause? I think it will work, correctly, without it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old May 7th, 2007, 04:54
Junior Member
Join Date: Apr 2007
Location: India
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Problem using Max()

If i dont use group by then i get this following error:

Error:1140
Mixing of GROUP columns (MIN(),MAX(),COUNT()...) with no GROUP columns is illegal if there is no GROUP BY clause

so need to use gorup by .

Thanks,
Thanuja.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old May 8th, 2007, 10:09
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Problem using Max()

I think I had an odd moment when I made that suggestion. Try

select activity_id from activity where chapter_id='10' order by proof_pages desc limit 1
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old May 11th, 2007, 10:39
Junior Member
Join Date: Apr 2007
Location: India
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Problem using Max()

Ya thats ok. I tried this query and it works. Thanks.

Thanuja.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
mysql

Thread Tools

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 On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
First image problem and inline list problem konnor5092 Web Page Design 8 Dec 1st, 2007 09:08


All times are GMT. The time now is 06:08.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42