SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL "or" query, can it be done?

    After searching through the SQL help documentation and beloved search engine Google, I have come to the conclusion that I am stumped on this question.

    Im looking to do a query similar to the following in structure:

    Code:
    SELECT * FROM testtable WHERE data="ok" OR data2="ok"
    Unfortunately, this query does not work. Is is possible to use an "or" expression in a MySQL query or should I just join the results from the two standard queries together?

    Thanks,
    Shawn

  2. #2
    SitePoint Wizard Crowe's Avatar
    Join Date
    Nov 2001
    Location
    Huntsville
    Posts
    1,117
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I do this all the time, and it seems to be working fine. Your syntax looks right - are you sure the data is matching?

    Here is one that I'm using, just for reference.

    PHP Code:
    $query="SELECT * FROM news WHERE validated='1' AND category='1' OR category='2' ORDER BY published DESC limit $howmany"
    Hope that helps..
    Chrispian H. Burks
    Nothing To Say

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    LMAO, I am ever dumb I was missing a stupid closing quote (yet the example I posted was fine), lmao. Thanks for the heads up...

    -Shawn

  4. #4
    SitePoint Member
    Join Date
    Mar 2002
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this, always works for me...

    SELECT * FROM testtable WHERE data = 'value' OR data2 = 'value'

  5. #5
    SitePoint Wizard Crowe's Avatar
    Join Date
    Nov 2001
    Location
    Huntsville
    Posts
    1,117
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Shawn, I'd be a much better programmer IF - I could spell, I could type, and I could remember variable names

    It's always the little things that kill me for hours on end.
    Chrispian H. Burks
    Nothing To Say


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
  •