Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Select based on first condition

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
ksathishkumar83

New User


Joined: 21 Nov 2006
Posts: 50
Location: India

PostPosted: Fri Dec 07, 2012 12:02 am    Post subject: Select based on first condition
Reply with quote

Hi,

I have table as below:

Code:
Col1    Col2        COl3
A          1            dd
A          3            ff
A          3            ss
B          3            ee



Code:
Select col3 from table1
          where col1 ='A' or Col2='3'.


Output:
---------
Code:
Col3
------
dd
ee



The second and third row should not be selected.If Col1='A' it should not check for COl2 condition.

I tried splitting into two queries.But i am trying to find the solution in single query.
Back to top
View user's profile Send private message

Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1775
Location: Bloomington, IL

PostPosted: Fri Dec 07, 2012 12:07 am    Post subject:
Reply with quote

Your post is ambiguous. Is the output you show the desired output or the actual output?
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10308
Location: italy

PostPosted: Fri Dec 07, 2012 12:08 am    Post subject: Reply to: Select based on first condition
Reply with quote

Your post is clear as mud ...

are You complaining that the <select> You posted does not satisfy Your requirement or what ?

post Your input data, what You expect, without foggy comments, please icon_cool.gif

if the output is what is expected

the logic should be ...

( col1 = "A" or col2 = "3" ) and ( not ( col1 = "A" and col2 = "3" ) )

I do not speak SQLese any longer, so a translator will be required
Back to top
View user's profile Send private message
Pandora-Box

Moderator


Joined: 07 Sep 2006
Posts: 1542
Location: Andromeda Galaxy

PostPosted: Fri Dec 07, 2012 12:09 am    Post subject:
Reply with quote

Your requirement is not clear for me atleast


When you say 2nd row and 3rd row does it mean the row id?

What is the SPECIAL business need about 2nd row and 3rd row?
Back to top
View user's profile Send private message
ksathishkumar83

New User


Joined: 21 Nov 2006
Posts: 50
Location: India

PostPosted: Fri Dec 07, 2012 12:11 am    Post subject: Reply to: Select based on first condition
Reply with quote

The output shown is the desired output.
Back to top
View user's profile Send private message
Pandora-Box

Moderator


Joined: 07 Sep 2006
Posts: 1542
Location: Andromeda Galaxy

PostPosted: Fri Dec 07, 2012 12:14 am    Post subject:
Reply with quote

Or Do you want to pick the data which doesnt have 'A' and '3' together

If yes tell me what did you try?
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10308
Location: italy

PostPosted: Fri Dec 07, 2012 12:15 am    Post subject: Reply to: Select based on first condition
Reply with quote

Pandora,
the TS does NOT want the data with A and 3
Back to top
View user's profile Send private message
Pandora-Box

Moderator


Joined: 07 Sep 2006
Posts: 1542
Location: Andromeda Galaxy

PostPosted: Fri Dec 07, 2012 12:21 am    Post subject:
Reply with quote

Code:
where (col1 = A and col2 <> 3)
or (col1 <> A and col2 = 3)


Should do

Thanks Enrico
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1775
Location: Bloomington, IL

PostPosted: Fri Dec 07, 2012 12:45 am    Post subject:
Reply with quote

Amazing; SQL does not have an XOR operator! icon_eek.gif
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Fri Dec 07, 2012 12:47 am    Post subject:
Reply with quote

Hello,

Quote:
If Col1='A' it should not check for COl2 condition.
Is this really true or is this a typo?
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts BUILD OUTFIL based on condition other... balaji81_k DFSORT/ICETOOL 13 Fri Sep 08, 2017 11:06 pm
No new posts Can we limit length in concatenation ... balaji81_k DB2 7 Tue Aug 22, 2017 2:50 am
No new posts Select numeric portion from CHAR data... balaji81_k DB2 6 Sat Aug 19, 2017 1:51 am
No new posts How do you create Eclipse based dialogs jasorn IBM Tools 0 Thu Aug 03, 2017 5:05 pm
No new posts Split file based on comparsion to 2 f... Div Grad DFSORT/ICETOOL 3 Thu Jul 27, 2017 9:16 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us