'make a query in sql as to get all list of rows with where condition
i have following table and need to get the all rows and the condition end_dt IS NULL OR end_dt >=CURRENT DATE has to apply only for the rows where PLAN_ID is EPTONDEL1.
Input table:

Output should be: enter image description here
Solution 1:[1]
Lets see if I understand your question... You want ALL rows where PLAN_ID='STARTTEST1' but rows where PLAN_ID='EPTONDEL1' should only show when end_dt IS NULL OR end_dt >=CURRENT DATE
Rearranging some logic and doing nesting logic gives you this
select * from table where PLAN_ID='STARTEST1'
OR (
PLAN_ID='EPTONDEL1' AND (end_dt IS NULL OR end_dt >=CURRENT DATE)
)
This should give you the desired result (if I understood correclty) :)
Alright changing the query after your comment to give you ALL records except EPTONDEL1, except where the condition is set...
select * from table where PLAN_ID<>'EPTONDEL1'
OR (
PLAN_ID='EPTONDEL1' AND (end_dt IS NULL OR end_dt >=CURRENT DATE)
)
Above gives you all records, and add the extra check only to EPTONDEL1.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
