User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Oracle section within the Web Development category of DaniWeb, a massive community of 422,796 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,330 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Oracle advertiser: Programming Forums
Views: 1662 | Replies: 9 | Solved
Reply
Join Date: Jan 2008
Location: India
Posts: 160
Reputation: sbv is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 7
sbv's Avatar
sbv sbv is offline Offline
Junior Poster

Question What is wrong here

  #1  
Feb 8th, 2008
Hi
i want to select the values from my table where a column must contains some value. So i wrote this
Select * from RG_TAB where CMCode = 4 and CMCode = 5

This query not giving me any result but

Select * from RG_TAB where CMCode = 4 Or CMCode = 5

is giving me result.
I am confused. What is happening. What should be the query?

Thanks and regards,
sbv
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: � Jogja �
Posts: 2,584
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Rep Power: 11
Solved Threads: 235
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: What is wrong here

  #2  
Feb 8th, 2008
Select * from RG_TAB where CMCode = 4 and CMCode = 5

This query not giving me any result but
if u use this clause (and operator) it means two condition must be available. if just one condition only (ex CMCode=4) then this command didn't give result. so CMcode = 4 & CMcode = 5 must be available to get result.

Select * from RG_TAB where CMCode = 4 Or CMCode = 5
is giving me result.
This clause will give result if one of condition available or two condition available. so you don't needed two condition to give a result, one condition can give result.
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote  
Join Date: Jan 2008
Location: India
Posts: 160
Reputation: sbv is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 7
sbv's Avatar
sbv sbv is offline Offline
Junior Poster

Re: What is wrong here

  #3  
Feb 8th, 2008
Originally Posted by Jx_Man View Post
if u use this clause (and operator) it means two condition must be available. if just one condition only (ex CMCode=4) then this command didn't give result. so CMcode = 4 & CMcode = 5 must be available to get result.


This clause will give result if one of condition available or two condition available. so you don't needed two condition to give a result, one condition can give result.


Hi
Thanks for reply.
My Table contents are as follows.....

RID MasterVal CMCode
-------------------------------------
1 Cricket 4
2 Marketing 5
3 bla bla

Now here from my table i want to select records where CMCode is 4 and 5. So is my query is wrong!!
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 197
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: What is wrong here

  #4  
Feb 9th, 2008
yes it is, use "where cmcode = 4 or cmcode = 5" which will give you all the rows where cmcode is either 4 or 5 (it can never be both at the same time, which is why your original query gave no results).
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote  
Join Date: Nov 2007
Posts: 63
Reputation: Sawamura is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
Sawamura's Avatar
Sawamura Sawamura is offline Offline
Junior Poster in Training

Re: What is wrong here

  #5  
Feb 9th, 2008
yes, as jwenting said. it can never be both at the same time.
Reply With Quote  
Join Date: Feb 2008
Posts: 3
Reputation: kevs1607 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 2
kevs1607 kevs1607 is offline Offline
Newbie Poster

Re: What is wrong here

  #6  
Feb 9th, 2008
Originally Posted by sbv View Post
Hi
i want to select the values from my table where a column must contains some value. So i wrote this
Select * from RG_TAB where CMCode = 4 and CMCode = 5

This query not giving me any result but

Select * from RG_TAB where CMCode = 4 Or CMCode = 5

is giving me result.
I am confused. What is happening. What should be the query?

Thanks and regards,
sbv


hi
use this query - Select * from RG_TAB where CMCode = 4 Or CMCode = 5
Reply With Quote  
Join Date: Nov 2007
Location: � Jogja �
Posts: 2,584
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Rep Power: 11
Solved Threads: 235
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: What is wrong here

  #7  
Feb 9th, 2008
i suggest to use or operand in query, don't use and.
Last edited by Jx_Man : Feb 9th, 2008 at 1:23 pm.
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote  
Join Date: Nov 2007
Posts: 51
Reputation: Nige Ridd is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 9
Nige Ridd Nige Ridd is offline Offline
Junior Poster in Training

Re: What is wrong here

  #8  
Feb 11th, 2008
An alternative which you may see commonly is instead of using multiple references to a field with 'or' is to write something like

Select * from RG_TAB where CMCode in ( 4, 5 )

You can imagine when you have 5 or 6 possible values that this is much shorter and easier to read.
Nige
Reply With Quote  
Join Date: Jan 2008
Location: India
Posts: 160
Reputation: sbv is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 7
sbv's Avatar
sbv sbv is offline Offline
Junior Poster

Re: What is wrong here

  #9  
Feb 12th, 2008
Originally Posted by Nige Ridd View Post
An alternative which you may see commonly is instead of using multiple references to a field with 'or' is to write something like

Select * from RG_TAB where CMCode in ( 4, 5 )

You can imagine when you have 5 or 6 possible values that this is much shorter and easier to read.
Nige


hi
thanks to all.
what i need is gained by using the query of IN and Not In.
Reply With Quote  
Join Date: Feb 2007
Location: Bangalore,India
Posts: 1,270
Reputation: debasisdas is on a distinguished road 
Rep Power: 4
Solved Threads: 80
debasisdas's Avatar
debasisdas debasisdas is offline Offline
Nearly a Posting Virtuoso

Re: What is wrong here

  #10  
Feb 12th, 2008
AND means all the conditon must satisfy.

OR means any of the condition should satisfy.
Share your Knowledge.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Oracle Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Oracle Forum

All times are GMT -4. The time now is 9:23 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC