Skip to content
Advertisement

Default value in select – SQL

I want to select the sum of the biggest and the lowest numbers in specific column of table, I get it well but I also need to set a default value in case if the column is empty, so far I tried this:

And if my table is empty I want to get a single value with default value like this:

I tried to some solutions for default value but I didn’t found for exactly this case. Sorry I’m new to SQL 🙂

Advertisement

Answer

You can use COALESCE():

I would be inclined to use only a single subselect:

And even to eliminate the subqueries entirely:

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