IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Select based on first condition


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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: 1788
Location: Bloomington, IL

PostPosted: Fri Dec 07, 2012 12:07 am
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

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Fri Dec 07, 2012 12:08 am
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

Global Moderator


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

PostPosted: Fri Dec 07, 2012 12:09 am
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
Reply with quote

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

Global Moderator


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

PostPosted: Fri Dec 07, 2012 12:14 am
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

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Fri Dec 07, 2012 12:15 am
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

Global Moderator


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

PostPosted: Fri Dec 07, 2012 12:21 am
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: 1788
Location: Bloomington, IL

PostPosted: Fri Dec 07, 2012 12:45 am
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

Moderator Emeritus


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

PostPosted: Fri Dec 07, 2012 12:47 am
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Dynamically pass table name to a sele... DB2 2
No new posts SELECT from data change table DB2 5
No new posts Select two different counts from SQL... DB2 6
No new posts To search DB2 table based on Conditio... DB2 1
This topic is locked: you cannot edit posts or make replies. Merge 2 input files based on the reco... JCL & VSAM 2
Search our Forums:

Back to Top