473,407 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

GROUP BY and ORDER BY

Here's another one; thanks so much to everyone who helped with my last
problem. I can't upgrade mySQL but I figured out a way around it from your
examples.

SELECT `subject` , max( `datetime` )
FROM `table`
WHERE 1
GROUP BY `subject`
ORDER BY `datetime` DESC LIMIT 0 , 30

The thing is...it doesn't order by `datetime`...it seems to be in a random
order. I've tried ORDER BY max(`datetime`) but that gives me an error that
says "#1111 - Invalid use of group function"

I could just sort it in PHP, but is there a better way?

Thanks
Jul 20 '05 #1
2 5415
"Experienced but Undocumented" <e0*@removethis.toao.net> wrote in message
Here's another one; thanks so much to everyone who helped with my last
problem. I can't upgrade mySQL but I figured out a way around it from your examples.

SELECT `subject` , max( `datetime` )
FROM `table`
WHERE 1
GROUP BY `subject`
ORDER BY `datetime` DESC LIMIT 0 , 30

The thing is...it doesn't order by `datetime`...it seems to be in a random
order. I've tried ORDER BY max(`datetime`) but that gives me an error that says "#1111 - Invalid use of group function"

I could just sort it in PHP, but is there a better way?


Use column aliases.

SELECT `subject` , max( `datetime` ) as mdi
FROM `table`
WHERE 1
GROUP BY `subject`
ORDER BY mdi DESC LIMIT 0 , 30

Incidentally, what is meaning of the apostrophe `
Jul 20 '05 #2

"Siemel Naran" <Si*********@REMOVE.att.net> wrote
Use column aliases.

SELECT `subject` , max( `datetime` ) as mdi


Perfect! Thanks so much for your help!
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip...
1
by: Jeff Uchtman | last post by:
Here are 4 different MS SQL query's: Set rsVer = Server.CreateObject("ADODB.Recordset") strSql = "Select p.Locality_Code, p.Name, Count(c.Locality_Code) as Verified_Count From County AS p LEFT...
1
by: Randell D. | last post by:
Folks When I perform a SELECT - whats the differences between GROUP BY and ORDER BY? Thanx randell d.
4
by: Chad Richardson | last post by:
I've always been mistified why you can't use a column alias in the group by clause (i.e. you have to re-iterate the entire expression in the group by clause after having already done it once in the...
1
by: Rick | last post by:
After being frustrated with this issue on several occasions I think I found the secret sauce for solving the issue after reading a few different messages about what others thought and trying a...
5
by: Mike Nolan | last post by:
I notice that 7.4 doesn't do default ordering on a 'group by', so you have to throw in an 'order by' clause to get the output in ascending group order. Is this something that most RDB's have...
3
by: Louis | last post by:
Is there a switch or a setting in Access so that a group by query doesn't return a field name SumOf(original field name)? Especially when you chain multiple queries together you'd get...
6
by: Tony Miller | last post by:
All I have an aggregate query using the function Month & Year on a datereceived field ie: TheYear: Year() TheMonth: Month() These are the group by fields to give me a Count on another field by...
12
by: Bill Moran | last post by:
Hey all. I've hit an SQL problem that I'm a bit mystified by. I have two different questions regarding this problem: why? and how do I work around it? The following query: SELECT GCP.id,...
3
by: ylekot88 | last post by:
Hi I am a student, I am trying to figure this out. I am trying to run a select statement that is asking for customer#, date, and total price of each order. ensure results are in chronological...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.