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: 1738
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: 10203
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: 1529
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: 1529
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: 10203
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: 1529
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: 1738
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 Removing Duplicates based on certain ... chandracdac DFSORT/ICETOOL 8 Fri Dec 09, 2016 4:40 am
No new posts Two Selects in a single select query Rohit Umarjikar DB2 1 Fri Nov 04, 2016 8:46 pm
This topic is locked: you cannot edit posts or make replies. How to pass the previous month date i... Suganya87 DFSORT/ICETOOL 5 Mon Oct 31, 2016 4:13 pm
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm
No new posts abend sort based on count records in ... anatol DFSORT/ICETOOL 5 Mon Oct 17, 2016 10:10 pm


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