Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Inverse this where condition

 
Ranch Hand
Posts: 56
  • 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?
 
Bartender
Posts: 4107
72
Hibernate Fedora Chrome
  • 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
  • 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:


 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • 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
  • 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'.
 
Bartender
Posts: 2658
19
Netbeans IDE C++ Linux
  • 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
Hibernate Eclipse IDE Java
  • 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
  • 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!
 
Ranch Hand
Posts: 874
Android VI Editor Java
  • 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
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isn't that what you have got?
 
and POOF! You're gone! But look, this tiny ad is still here:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic