SELECT mutliple entries from same field

Discussion in 'Databases' started by adbox, Aug 17, 2009.

  1. #1
    I'm trying to work with the wordpress database, specifically the wp_options table, and their structure looks like this:

    id option_name option_value

    and I need to pull about 8 enteries out of this table with a single query.

    I try this, but it pulls back wrong results:

    "SELECT option_value FROM wp_options WHERE option_name='blog_url' || option_name='blog_title' || option_name='blog_tagline' || option_name='blog_email' || option_name='blog_permalink' || option_name='blog_comments' || option_name='plugin_loading' || option_name='random_theme'"

    I am trying to pull these values out so I can set them into variables

    I don't know why the returned results come back wrong(some come back wrong, giving me values for the wrong option_name)

    Is there a better way to do this?

    ty
    adbox
     
    adbox, Aug 17, 2009 IP
  2. gelous09

    gelous09 Peon

    Messages:
    31
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    SELECT `option_name` , `option_value`
    FROM `wp_options`
    WHERE `option_name` = 'blogname' || `option_name` = 'admin_email' || `option_name` = 'rss_excerpt_length'
    LIMIT 0 , 30

    outputs

    option_name option_value
    admin_email
    blogname asdasda
    rss_excerpt_length 50
     
    gelous09, Aug 18, 2009 IP
  3. adbox

    adbox Well-Known Member

    Messages:
    906
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    155
    Digital Goods:
    1
    #3
    yes this did much better thank you!
     
    adbox, Aug 18, 2009 IP
  4. marshalprince

    marshalprince Peon

    Messages:
    435
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    how this query is working pls let me know. Also let me know the difference between `wp_options` and wp_options
     
    marshalprince, Aug 18, 2009 IP
  5. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #5
    You don't need to use backticks unless you want to or you name a column using a reserved word like date, time, etc..

    You can also do this:
    SELECT `option_name` , `option_value`
    FROM `wp_options`
    WHERE `option_name` IN ('blogname','admin_email','rss_excerpt_length')
    LIMIT 0 , 30 ;
     
    jestep, Aug 20, 2009 IP
  6. adbox

    adbox Well-Known Member

    Messages:
    906
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    155
    Digital Goods:
    1
    #6
    even better!
     
    adbox, Aug 20, 2009 IP
  7. Chocolate Lime

    Chocolate Lime Active Member

    Messages:
    399
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #7
    Always use an IN statement over OR's (||)
     
    Chocolate Lime, Aug 21, 2009 IP