Fixed small sql bug