Click here to Skip to main content
15,923,168 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The table structure is like this;
 slp_no  doc_type    clearing Date          ui               batch_no

   1       2        2020-02-25  2020022571350010008500001     7135001-000850
   1       3        2021-03-26  2021032571350010008500001     7135001-000850 
   1       3        2021-03-25  2021032571350010008500001     7135001-000850
   1       3        2021-03-25  2021032571350010008500002     7135001-000850
   1       3        2021-03-25  2021032571350010008500003     7135001-000850
   2       2        2020-02-25  2021032571350010008500002     7135001-000850
   2       3        2021-03-26  2021032671350010008500002     7135001-000850 
   2       3        2021-03-26  2021032671350010008500003     7135001-000850 
   3       2        2020-02-25  2021032571350010008500003     7135001-000850 
   3       3        2021-03-25  2021032571350010008500004 	  7135001-000850 
                 
                 
 So for my result set I would want                
                 
  slp_no  doc_type    clearing_Date             ui            batch_no

   1       2        2020-02-25  2020022571350010008500001     7135001-000850
   1       3        2021-03-25  2021032571350010008500001     7135001-000850
   1       3        2021-03-25  2021032571350010008500002     7135001-000850
   1       3        2021-03-25  2021032571350010008500003     7135001-000850
   3       2        2020-02-25  2021032571350010008500003     7135001-000850 
   3       3        2021-03-25  2021032571350010008500004 	  7135001-000850 


What I have tried:

SELECT * FROM IMG_PDC_OUTWARDCLEARING AS T1
WHERE 1=1 AND 
(BATCH_NO = '7135001-000850') AND (CLEARING_DATE = '2021-03-25') 
UNION
SELECT *
FROM IMG_PDC_OUTWARDCLEARING AS T2
WHERE 1=1 
AND (BATCH_NO = '7135001-000850') 
AND (DOC_TYPE = '2') 
Posted
Updated 29-Apr-21 22:03pm
v11

1 solution

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.
 
Share this answer
 
v2
Comments
chamindat 30-Apr-21 2:03am    
Actually, I don't mention all data columns, it's enough to filter from clearing date
OriginalGriff 30-Apr-21 2:19am    
I kinda noticed - but since the columns you do show aren't part of the data you seem to be testing for, that means we have no real idea what the heck you are working with, or trying to do!


Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
chamindat 30-Apr-21 2:22am    
I amendment Describe the problem, please check

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900