Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2007
    Posts
    130

    Unanswered: 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.

  2. #2
    Join Date
    Mar 2004
    Posts
    480
    The second statement is correct. The first statement does not compare 'John' to a column or other string.

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Edit: oops, i was wrong

    hey, how come i can't delete my own post?
    Last edited by r937; 09-24-10 at 23:27.
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    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.

  5. #5
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    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
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    correction, i just tried it on this post, there was no Delete immediately after

    sorry for all the OT
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •