Skip to content
Advertisement

How to return default value from SQL query

Is there any easy way to return single scalar or default value if query doesn’t return any row?

At this moment I have something like this code example:

How to do that in better way without using IF-ELSE?

Advertisement

Answer

Assuming the name is not nullable and that Id is unique so can match at most one row.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement