Fixed a small SQL query bug