| Databases InterBase (29) MS-SQL (5) mysql (37) Oracle (1) |
MAX() in an InterBase query delivers the smallest value
Question: I run the following query (see box below) and it returns the expected results.Then I want to retrieve only the max() value and it returns the smallest value instead. Why is that? Answer: I looked into the problem and suspected that the ID field 'units_scenarios_id' is not a numerical field. Indeed it was defined as a varchar().You can add +0 to force Interbase to treat it as a number or do a clean type cast as shown below: select max(cast(FIELDNAME as integer))
Comments:
| ||||||||||||||||||