SELECT hostid,t1.hw_code,incoming,outgoing,total,quota,percent_used,time_created FROM bandwidth_log JOIN (SELECT hw_code, MAX(id) AS id FROM bandwidth_log GROUP BY hw_code) AS t1 USING(hw_code,id) WHERE percent_used>=80 ORDER BY percent_used DESC