Fixed bug with SQL statement returning all rows