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.
|
|
|
|
|
![]() |
||
Problem using Max()
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
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 |
|
|
|
#2
|
|||
|
|||
|
Re: Problem using Max()
Why are you using the group clause? I think it will work, correctly, without it.
|
|
#3
|
|||
|
|||
|
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. |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
|||
|
|||
|
Re: Problem using Max()
Ya thats ok. I tried this query and it works. Thanks.
Thanuja. |
![]() |
| Tags |
| mysql |
| Thread Tools | |
|
|
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 |