You can use NOT EXISTS :
SELECT * FROM table WHERE criteria2 = criteria2 and not exists ( SELECT * FROM table WHERE criteria = criteria ) union all SELECT * FROM table WHERE criteria = criteria;
Here NOT EXISTS provides the return of any part of UNION ALL. If the second criteria = criteria passes, then NOT EXISTS will return false and, therefore, only the second part of the above query will return the result. If this is not so, then there are no rows with criteria = criteria , and NOT EXISTS will return true and, therefore, only the data of the first part will be returned.
source share