Fixed some sql