Fixed select query bug