Simplify SQL queries to make them nicer for MySQL