File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inverse this where condition

 
Abu Nene
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 3908
9
Chrome Fedora Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are these columns numeric or char type? Which database you are using?
 
Abu Nene
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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'?
 
Abu Nene
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2575
11
C++ Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 874
Android Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ohh I got it! Hahaa... stupid me. Thanks guys!
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isn't that what you have got?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic