SELECT pname, name, description, command FROM (
SELECT a.id, p.id pid, p.name pname, a.name name, a.description, a.command FROM achievements a, players p, stats s WHERE
s.player_id = p.id AND CAST(s.type AS CHAR) = a.type AND s.block = a.block AND s.data = a.data AND s.value >= a.value
UNION SELECT a.id, p.id pid, p.name, a.name name, a.description, a.command FROM achievements a, players p WHERE
(a.type = \'MINECART_ENTER\' AND p.MINECART_ENTER >= a.value) OR
(a.type = \'MINECART\' AND p.MINECART >= a.value) OR
(a.type = \'BOAT_ENTER\' AND p.BOAT_ENTER >= a.value) OR
(a.type = \'BOAT\' AND p.BOAT >= a.value) OR
(a.type = \'KILLS_TOTAL\' AND p.KILLS_TOTAL >= a.value) OR
(a.type = \'BLOCKDESTROY_TOTAL\' AND p.BLOCKDESTROY_TOTAL >= a.value) OR