tags:

views:

43

answers:

1

In my table I have looked manually and found that the top three idle units have been idle for 17, 13 and 13 days. When I use this SQL statement to try and pull the three rows with the highest idle column value, I don't get these numbers, I get 8, 7 and 7. Is there some other command I should use to grab the first 3 rows of a sorted resultset?

SELECT * FROM reporttables.idlereport WHERE LEFT(depot,3)='Roc' ORDER BY idle DESC LIMIT 3

Can anyone help me figure out what is wrong with this statement

+2  A: 

Is the 'idle' field of a numeric or a char data type?

The sort order you found suggests char, then "7" could be 'greater than' "17".

You might then be able to cast the char data with some sort of CONVERT. Exact syntax depends on your RDBMS type.

martin clayton
VARCHAR(10) DB is MySQL I never thought of that. I'll try converting it and comparing then.
Geoff
I changed the data type to an Integer type and it works now. I can't believe I missed that, all I can hope for now is that I live and learn. I don't know why I ever put that column to char type anyway, it's always an integer. Thanks for everyone's help
Geoff