Formatted mysql query