MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old August 14th, 2000, 07:34 AM
Martijn Martijn is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 1999
Posts: 14 Martijn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
SELECT max(id) FROM table WHERE id<$id

When there is no max(id) it still returns an empty value...why?, and how do i solve this?


Reply With Quote
  #2  
Old August 14th, 2000, 08:25 AM
christucker2 christucker2 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2000
Posts: 81 christucker2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
I'm afraid you're going to have to give a little more detail on this one. What do you mean by "When there is no max(id) it still returns an empty value"? How is there no max id, and what is the empty value it returns? Does it just return no rows, or does it return zero, or what?

You may be able to fix the problem by being more explicit about the use of the max function, though without further details I can't be sure. max is an aggregate function and so expects an aggregate group to operate on. Therefore, you should always specify a group by clause on your select -- in this case, MySQL may automagically put one there, but it's better to be explicit. So, change your query to:
select max(id) from table where id < $id group by id;

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > SELECT max(id) FROM table WHERE id<$id


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway