Optimal solution using coalesce() :
Select * from table_name where field1 = coalesce ( (select field1 from table_name where field1='value1' limit 1) , 'default' );
Note limit 1 in the subquery: in this case, it is imperative that the subquery does not return more than one row. But even using the case when exists (...) approach, it is good practice to add it otherwise, the database engine may be forced to scan all rows matching the subquery.
Of course, most modern databases are smart enougth to quietly optimize it. But some old ones could not. And in general, these may be cases when they cannot.
That is, for example, in PostgreSQL, if the subquery uses not (or not declared as) stable functions, the scheduler will be forced to perform a full scan to obtain consistent results if this function has any effect s | ide.
source share