SELECT o.*, IF(o.newcost!=0,o.newcost, o.cost) cost2 FROM etag_object o AND status!=0 ORDER BY cost2 ASC SQL Error #1064: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'AND status!=0 ORDER BY cost2 ASC' at line 1