Something else to consider here:
MySQL can use indexes to optimize order by as well, but your order by value can't be
indexed since
it is derived from a database lookup/calculation. If you really need to order by
"diferenca"
you may have to live with it, although you may still see "Using fileso
What table type is this? If it's MyISAM select count(*) should be instantaneous. If
it's InnoDb and you've got a large dataset (say 1 million+) then select count(*) will
be slow b/c it doesn't store the # of records in the table, thus it has to count
records. MyISAM does store the count so it