new SQL including bug fix

yeee