|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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? |
|
#2
|
|||
|
|||
|
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; |
![]() |
| Viewing: Dev Shed Forums > Databases > MySQL Help > SELECT max(id) FROM table WHERE id<$id |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|