Minor bugfix, was using the wrong condition in SQL