Fixed an issue in the database query for the where clause