corrected yet another stupid bug in sql query