473,385 Members | 1,927 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,385 software developers and data experts.

The SELECT statement doesn't seem to function correctly in the example below.

1
table weather (date, temphi, templo).

Looks like this:
2010-7-24, 83, 57
2010-7-25, 94, 60
2010-7-26, 98, 58
2010-7-27, 93, 61
2010-7-28, 87, 59

Statement is:
SELECT date, max(temphi) from weather;

I expected 2010-7-26, 98 but got 2010-7-24, 98, clearly the wrong date on which the high temperature was reported.
All tables with all such data erroneously return the first row's element (in this case the first date) but correctly give the high temp, 98.

Is there a way to do this that works? Thanks
Sep 14 '10 #1
1 1015
code green
1,726 Expert 1GB
It does function correctly.
This is actually an illegal query in some SQL because you are using an aggregate function for temphi,
but date is not part of a GROUP BY or aggregate.
However MySQL uses some algorithm to 'guess' which date you want but the result can be unpredictable.
I think you will have to use
Expand|Select|Wrap|Line Numbers
  1. GROUP BY ... HAVING or
  2. a sub-query WHERE temphi = (SELECT MAX(temphi))
My brain refuses to write the correct full syntax for this but I hope I have helped.
Sep 14 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: avinash | last post by:
hi my self avi i want to copy data from one table to other table,by giving certain condition and i want o use insert statement .in this i want to pass some value directly and some value from...
1
by: John Hall | last post by:
We need to read a SQL database containing a mix of English words and Chinese Characters. We think we need to use the N'xxxx' to read the Unicode. We have one place where the SELECT statement...
8
by: Mattias Campe | last post by:
Hello, On http://student.ugent.be/astrid/bewoners.php I got the problem that I want Javascript to let my browser go to http://student.ugent.be/astrid/bewoners.php?beginAcjaar=2002 when I select...
4
by: dot | last post by:
I'm trying to use the following hack to create an expanding/contracting list of links: <html> <head> <script language="Javascript" type="text/javascript"> function ChangeText(obj,...
15
by: grunar | last post by:
After some thought on what I need in a Python ORM (multiple primary keys, complex joins, case statements etc.), and after having built these libraries for other un-named languages, I decided to...
4
by: Dave [Hawk-Systems] | last post by:
have a data table that records entries by date(unix timestamp) and customer number. each custnum will have several entries showing a running ledger type snapshot. we have the need to get the most...
6
by: Maya | last post by:
Hello guys, I have table "Shopping" that has 3 columns (Item, Category, Price) Is there a straight forward way in T-SQL to select the Item that has the highest price for each category as below:...
5
by: JamesHoward | last post by:
I have a problem with python's asyncore module throwing a bad file descriptor error. The code might be difficult to copy here, but the problem is essentially: The server wants to sever the...
1
by: EORTIZ | last post by:
I would like to know the way that I can write a CASE function in a select statement that uses another variable that is created in the same SELECT statement using another CASE function. This is...
5
by: chazzy69 | last post by:
Ok here is what im trying to achieve, i first retrieve from one part of my database names and email address, etc which i store in an array i.e. while($row= mysql_fetch_array($result)){ $name =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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,...
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
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,...
0
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...

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.