That SQL doesn't look like you thought too much before writing it: why does it include "
WHERE 1=1 AND ...
" given that it will always resolve to
TRUE
?
Where is the
BATCH_NO
? It doesn't appear in the table data you show at all.
Same thing for
CLEARING_DATE
?
How do you expect your
IN
condition to work at all, when it returns every column from the matching rows of the same table?
Stop guessing, think about your actual data - and I'm going to assume it doesn't look like your sample data because of the questions above - and think about what actually decides which rows you should return.
We have no idea what you are trying to do, but it's possible that you need to look at the DISTINCT keyword:
SQL SELECT DISTINCT Statement[
^] - but at the moment, we can't help you based on what you have given us.