Re: select MAX(field-name)
Posted in 1995
In <3nlb81$3vp@news.q8petroleum.com.kw> al-jouhar
<adel@q8petroleum.com.kw> writes:
>
>when I run SELECT MAX(col1) from table-name
>where col2 = something
>It returns 1 row(s) retrieved and the output is null, however
>select col1 from table-name
>where col2 = something>It returns No rows found.......!!!
>
The aggregate function returned the maximum value--undefined. You will
always get a row when you use an aggregate function; whether the row
returned has useful data or a null depends upon the data in the table.
This does leave the question of whether there were rows with null
values for that column or simply no rows that met the criteria, but
this can be handled by doing SELECT MAX(col1), COUNT(*) ... and
checking the count value (which should be 0 if no rows were found
rather than a null).
John Prideaux
alastl@ix.netcom.com