I need to write a query which would always return something, even if nothing satisfies conditions, something like this
SELECT * WHERE date > NOW() FROM table ORDER by date
IF none is returned THEN
SELECT FIRST FROM table ORDER by date
So only numbers more then 10 will be returned, if none is returned, return any number
Any ideas how to do it?
Here is one way, using
union all:If you are using a reasonable version of SQL, you could do something like:
You need window functions for this.