Fixed up SQL for sqlite