wood burning stoves 2.0*
The moose likes JDBC and the fly likes Inverse this where condition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Inverse this where condition" Watch "Inverse this where condition" New topic
Author

Inverse this where condition

Abu Nene
Ranch Hand

Joined: Nov 13, 2008
Posts: 56


I need to select records from table a where both columns b and c are not 0. Using the above SQL statement, I cannot seem to do that. Any advise other the using 2 select statements with the exists condition?
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3848

Are these columns numeric or char type? Which database you are using?


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Abu Nene
Ranch Hand

Joined: Nov 13, 2008
Posts: 56
Vijitha Kumara wrote:Are these columns numeric or char type? Which database you are using?


Type is VARCHAR2, database is Oracle 10g.

Also tried the following:


Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Both operators are semantically the same so both queries should produce the results you want. What results are you seeing? Are you still getting records where both b and c are == '0'?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Abu Nene
Ranch Hand

Joined: Nov 13, 2008
Posts: 56
Paul Sturrock wrote:Both operators are semantically the same so both queries should produce the results you want. What results are you seeing? Are you still getting records where both b and c are == '0'?


Yes both return the same result. As per my first post, I need to select records from table a where both columns b and c are not 0. Yes, I'm getting records where both b and c are == '0'.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2510
    
  10

ABu NeNe...Yes both return the same result. As per my first post, [b wrote:I need to select records from table a where both columns b and c are not 0[/b]. Yes, I'm getting records where both b and c are == '0'.
How is that possible?
Can you print the complete sql query you used, and (a sample of) the results you are getting.
If possible, put it in the post as-is, without changes.


OCUP UML fundamental and ITIL foundation
youtube channel
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


I need to select records from table a where both columns b and c are not 0

This is not possible given your data type. You can manage to select records from table a where both columns b and c are not '0'.


Yes, I'm getting records where both b and c are == '0'.

This is also not possible, unless Oracle is behaving like no other database, which seems very unliklely. Are you sure you are not getting results where b or c equals an zero character followed or preceded by from white space? Or b or c equals the letter O?
Abu Nene
Ranch Hand

Joined: Nov 13, 2008
Posts: 56
For eg. the following is the table data



select D from A where B = '0' and C = '0' will return 00
select D from A where B != '0' and C != '0' will return 11
select D from A where (B != '0' and C != '0') will return 11

What I wanted is something like the 3rd SQL statement but return 10, 01 and 11 without using nested select statement with exists condition. Please advise.

Thanks in advance!
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874

Abu,

select D from A where (B != '0' and C != '0') will return 11 only. Whats your problem. ?

What I wanted is something like the 3rd SQL statement but return 10, 01 and 11 without using nested select statement with exists condition. Please advise.


Do you mean you need the above query should return 10, 01 and 11 ?

Abu Nene
Ranch Hand

Joined: Nov 13, 2008
Posts: 56
Ohh I got it! Hahaa... stupid me. Thanks guys!
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Isn't that what you have got?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inverse this where condition