• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Inverse this where condition

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Isn't that what you have got?
reply
    Bookmark Topic Watch Topic
  • New Topic