473,624 Members | 2,656 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5422
"Experience d 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*********@RE MOVE.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
14159
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 Smarty-2.6.7.tar.gz on a system running WindowsXP SP2. Apache and PHP tested out fine. After adding Smarty, I ran the following http://localhost/testphp.php
1
1215
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 JOIN Verified as c on p.Locality_Code=c.Locality_Code Group BY p.Locality_Code, p.Name ORDER BY p.Locality_Code" rsVer.Open strSQL, Conn
1
7735
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
28818
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 select statement). I'm mostly a SQL hobbiest, so it's possible that I am not doing this in the most efficient manner. Anyone care to comment on this with relation to the following example (is there a way to acheive this without re-stating the...
1
6913
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 combination of them all. What worked for me was the following: 1. Put a Break Point in MFC source file DLGDATA.CPP on line 338 which is: TRACE0("Warning: skipping non-radio button in group.\n"); (Copyright
5
3217
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 historically done (including PG prior to 7.4) but isn't really part of the SQL standard? On a mostly unrelated topic, does the SQL standard indicate whether NULL should sort to the front or the back? Is there a way to force it to one or the other...
3
8033
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 SumOfSumOfSumOf.... Anyone know? TIA.
6
17911
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 year & month When I try to place a date filter 'Between x And y ' on an expression field
12
25251
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, GCP.Name FROM Gov_Capital_Project GCP,
3
3861
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 order based upon order date. When I run the following with just a group by clause, it works. If I add order by orderdate, I get an error message that states SQL Error: ORA-00979: not a GROUP BY expression. Why is the order by clause giving me a...
0
8246
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8179
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8685
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8631
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8341
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8490
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6112
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4184
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.