Skip to content
Advertisement

If rows exist in table then return value from table ELSE return a default value. – MySQL

I have to write a query which will return the latest timestamp column’s value from a table if rows exist.

If there is no row(s) in table then it return the default value.

I have write the following query in MS-SQL which is working fine for me.

But , now I need to write this query in MySQL.

I have tried a-lot of methods but no luck.

In MySQL:

Can anyone please comment how can I do this.

Advertisement

Answer

Use UNION ALL:

or, if timestamp is not nullable:

See the demo.

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