Fixed SQLITE query to match MySQL query