sql query bug fixed for the previous commit