Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups 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: 1771
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: 10277
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: 1537
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: 1537
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: 10277
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: 1537
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: 1771
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 Split file based on comparsion to 2 f... Div Grad DFSORT/ICETOOL 3 Thu Jul 27, 2017 9:16 pm
No new posts SQL - select data available in index Nileshkul DB2 3 Mon Jun 26, 2017 1:30 am
This topic is locked: you cannot edit posts or make replies. Need help on If condition continuatio... ashok_uddaraju CLIST & REXX 4 Fri May 19, 2017 8:55 am
No new posts Group Data based on a key Arun Raj DFSORT/ICETOOL 7 Thu Apr 27, 2017 11:29 pm
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us