Skip to content
Advertisement

How to set a default row for a query that returns no rows?

I need to know how to return a default row if no rows exist in a table. What would be the best way to do this? I’m only returning a single column from this particular table to get its value.

Edit: This would be SQL Server.

Advertisement

Answer

One approach for Oracle:

Or alternatively in Oracle:

Or alternatively in SqlServer:

These use the fact that MIN() returns NULL when there are no rows.

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