07-31-2023, 09:14 AM
I have a case where i have to fetch records for column field1='value1' if there are no values for 'value1' then i should fetch the record for 'default'.
For the above scenario I have used two queries:
`Select * from table_name where field1="value1"`
If the above query does not give back any record I fire the following query:
`Select * from table_name where field1="default"`
Now I want to do the above stated in one query. Can someone please help me with the same. I believe the answer lies somewhere in using `CASE WHEN` clause.
Also the above queries should work for oracle, postgres as well as mysql.
For the above scenario I have used two queries:
`Select * from table_name where field1="value1"`
If the above query does not give back any record I fire the following query:
`Select * from table_name where field1="default"`
Now I want to do the above stated in one query. Can someone please help me with the same. I believe the answer lies somewhere in using `CASE WHEN` clause.
Also the above queries should work for oracle, postgres as well as mysql.