Fixing bug with SQL statement.