I have a db of deceased persons; one of the columns contains their age at death. Since the db records the information in the historical documents "as is", the column contains things other than numbers. An age might be entered as "inf.", "6 mos.", "2 wks." etc, or be empty. About 90% of the column is plain old numbers like "87" or "2".
I'm trying to echo out a table of the oldest persons, sorted by age. Because of all the non-numeric values of age my query is:
<?php
...
$sql = "SELECT pid,first_name,surname,date,age
FROM $table
WHERE age REGEXP '^[0-9]+$'
ORDER BY age DESC
LIMIT 10";
...
?>
After age 90 the results are always kids who died aged 9. The column is being sorted in alphabetical order.
How do I sort in descending numerical order?