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: 1790
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

Senior Member


Joined: 14 Mar 2007
Posts: 10562
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: 1567
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: 1567
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

Senior Member


Joined: 14 Mar 2007
Posts: 10562
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: 1567
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: 1790
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 Copy members from Input PDS to Output... Poha Eater JCL & VSAM 9 Tue Jan 29, 2019 3:56 pm
No new posts SPLIT based on Trailer pshongal DFSORT/ICETOOL 2 Wed Jan 23, 2019 11:50 am
No new posts calculate the record count and based ... naveensrimf DFSORT/ICETOOL 1 Tue Jan 08, 2019 11:20 pm
No new posts Process Last Key of a record based on... naveen katkuri DFSORT/ICETOOL 5 Mon Nov 12, 2018 9:54 am
No new posts Concatenaing multiple rows to single ... Vignesh Sid DFSORT/ICETOOL 1 Tue Aug 14, 2018 8:59 am

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