Fix up SQL to work in MySQL