Home > Back-end >  Improve SQL: OR clause being used in AND clause
Improve SQL: OR clause being used in AND clause

Time:07-01

Is there a better way to write the following sql query

AND (
        product_return_date IS NULL
        OR product_return_date > SYSDATE
    )

CodePudding user response:

It's not 'better' per se, but you could write this:

WHERE COALESCE(product_return_date, SYSDATE   1) > SYSDATE

CodePudding user response:

Can you convert the statement thus:

AND nvl(product_return_date, SYSDATE 1) > SYSDATE;

In null case the date will be always greater than sysdate.

Thank you

  • Related