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 > Name= 'Bob' OR 'John' for Where clause

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-24-10, 19:19
cy163 cy163 is offline
Registered User
 
Join Date: Apr 2007
Posts: 127
Name= 'Bob' OR 'John' for Where clause

Hello ALL,


I wonder which statement is right in the following two choices


Code:
(1)  SELECT Salary FROM Employee Where  Name= 'Bob' OR 'John' 

(2) SELECT Salary FROM Employee WHERE Name= 'Bob' OR Name= 'John'

I have tried with both of them. Both run successfully, but result in different results.
Reply With Quote
  #2 (permalink)  
Old 09-24-10, 22:00
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
The second statement is correct. The first statement does not compare 'John' to a column or other string.
Reply With Quote
  #3 (permalink)  
Old 09-24-10, 22:24
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Edit: oops, i was wrong

hey, how come i can't delete my own post?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Last edited by r937; 09-24-10 at 22:27.
Reply With Quote
  #4 (permalink)  
Old 09-25-10, 10:27
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,606
Quote:
Originally Posted by r937 View Post
Edit: oops, i was wrong

hey, how come i can't delete my own post?
You're used to being a moderator, which allows you to delete posts until the post is processed by the post archiver, which takes months or years.

Users can only delete their posts for a relatively short period of time (until the VB post indexer processes the post, almost always less than a day).

-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #5 (permalink)  
Old 09-25-10, 15:27
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 620
Hi,

the second query is correct but the first one could have been rewritten as follows:

Code:
SELECT Salary FROM Employee Where  Name IN ('Bob', 'John')
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
  #6 (permalink)  
Old 09-25-10, 17:12
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
correction, i just tried it on this post, there was no Delete immediately after

sorry for all the OT
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
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