How To Skip With Other Further Records When Reached Condition?
I have SQL issue. Lets suppose we have record: In above record we need to select record with Cancel but only 2 starting not all with Cancel. There may be multiple Cancel on Top or
Solution 1:
With NOT EXISTS
:
select t.*from tablename t
where col ='Cancel'andnotexists (
select1from tablename
where creation_date < t.creation_date and col <> t.col
)
See the demo.
Solution 2:
That should be working. I just ordered ASC on "column 1" but you can remove that line if you don't care about which index is selected.
SELECT *
FROM YourTable
WHERE col2='Cancel'ORDERBY col1
LIMIT 2
Solution 3:
If you want the initial set of "cancels", you can do:
select t.*from t
where t.col2 ='cancel'and
t.col1 < (selectmin(t2.col1)
from t t2
where t2.col2 <>'cancel'
);
Post a Comment for "How To Skip With Other Further Records When Reached Condition?"