mysql - Returning a default value in SQL when no rows found -


how can change sql return default value if no rows found?

eg:

select text,name text_file text='met' 

if no rows found, text contain 'values not found' example

one method uses union all:

select text, name text_file text = 'met' union select max('values not found'), null text_file text = 'met' having count(*) = 0; 

notes. second subquery aggregation query. returns 1 row (without having). row has looking for.

second, type of operation should done in application , not database.

third, if expecting 1 row, can use aggregation query such as:

select (case when count(*) > 0 text else 'values not found' end) text,        (case when count(*) > 0 name end) name text_file text = 'met' 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -