SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Jul 2013
    Location
    South of the equator, then turn left
    Posts
    361
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can I use IN with strings?

    Hi everyone,

    please help me with a query. Do you think the following should work, or is it only possible with integers? I am trying to return those columns where one row has a field named beer, and one row has a field named wine. Do to the current setup, I'm unable to use the row ID. Or is this impossible?

    The echoed-out query looks like this:

    WHERE name = 'simon' && booz IN (beer,wine)

    Thank you in advance!!

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,260
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by RedBishop View Post
    I am trying to return those columns where one row has a field named beer, and one row has a field named wine.
    rows cannot possibly have differently named columns

    but yes, you can use IN with strings, and even with column names

    pro tip: use AND instead of &&
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Addict
    Join Date
    Jul 2013
    Location
    South of the equator, then turn left
    Posts
    361
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Rudy,

    thank you. For some reason I get the error:

    mysql_num_rows() expects parameter 1 to be resource, boolean given.

    Must the strings be quoted perhaps?

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,260
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by RedBishop View Post
    mysql_num_rows() expects parameter 1 to be resource, boolean given.
    i don't do php but you get this because your query died before it executed and you're not testing for successful execution (don't ask me how to do that) before using mysql_num_rows()

    Quote Originally Posted by RedBishop View Post
    Must the strings be quoted perhaps?
    if they're strings and not column names, yeah

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Addict
    Join Date
    Jul 2013
    Location
    South of the equator, then turn left
    Posts
    361
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay thank you, perhaps that is the reason for the error.


    Hope you have a good weekend.

    Cheers


Bookmarks

Posting Permissions

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