finacialscheduletype | finacialscheduletypevalue |
---|---|
2 | 05/06/2022 |
2 | 05/04/2022 |
2 | 05/07/2022 |
2 | 05/17/2022 |
0 | PROJECTED |
2 | 05/13/2022 |
2 | 03/05/2011 |
i have this table i want to select data
firstly if financialscheduletype = 2 is there in table then firstly query must check wether financialscheduletype = 2 is there in table or not then
select * from table where financialscheduletype=2 query should run
else
select * from table where financialscheduletype=0 query should run
CodePudding user response:
You can use case
in the where
clause.
Query -
select * from finance
where finacialscheduletype =
case when (select count(*) from finance where finacialscheduletype = 2) > 0 then 2 else 0 end;
DB-fiddle here.
CodePudding user response:
What you are after is not clear and you don't explain it. You might be describing this:
select * from finance
where financialscheduletype=2 or financialscheduletype=0;
which is same as:
select * from finance
where financialscheduletype in (2, 0);
Or you might be describing this:
select * from finance
where financialscheduletype = case
when exists (
select * from myTable
where financialscheduletype = 2) then 2 else 0 end;