If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > WHERE clause question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-14-07, 17:44
hconnor hconnor is offline
Registered User
 
Join Date: Feb 2007
Posts: 34
WHERE clause question

hi,

when i use this WHERE clause,

UPDATE physician

SET physician_practiceArea_1 = 'heart attack'

WHERE physician_spec = ('Cardiology' OR 'Invasive Cardiology' or 'Noninvasive and Invasive Cardiology')

the entire column of physician_spec is updated (not just cardiology), without regard to the where clause. if i break it out and run each separately, it works fine.
for example,

.... WHERE physician_spec = cardiology

is there a way to make modiy that WHERE statement to make it work? Thanks.

Mike
Reply With Quote
  #2 (permalink)  
Old 04-15-07, 01:15
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
yes change your = to the word IN and then leave your clause as is.
Reply With Quote
  #3 (permalink)  
Old 04-15-07, 06:01
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
and change the ORs to commas, i.e.

WHERE physician_spec IN ('Cardiology' , 'Invasive Cardiology' , 'Noninvasive and Invasive Cardiology')

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 04-16-07, 04:22
aschk aschk is offline
Registered User
 
Join Date: Mar 2007
Location: 636f6d7075746572
Posts: 770
Just to clarify for you where your statement was going wrong:
WHERE physician_spec = ('Cardiology' OR 'Invasive Cardiology' OR 'Noninvasive and Invasive Cardiology')
i believe this gets intepreted as WHERE physician_spec = (TRUE).
What you ought to have had would have been :
WHERE (physician_spec = 'Cardiology') OR (physician_spec = 'Invasive Cardiology') OR (physician_spec = 'Noninvasive and Invasive Cardiology')

However, the "IN" answer that has been provided by Rudy is the best...
Reply With Quote
  #5 (permalink)  
Old 04-16-07, 06:11
hconnor hconnor is offline
Registered User
 
Join Date: Feb 2007
Posts: 34
thanks a million. great forum.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On