SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: queries AND OR

  1. #1
    SitePoint Guru defiance's Avatar
    Join Date
    Oct 2004
    Location
    United states
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    queries AND OR

    hi..

    i have a question.

    If let say i want to select fields in my database, with the condition of type=articles AND content=%keyword% OR subject=%keyword%

    what i want is that i want to choose only entries which type HAS to be = articles AND content or subject, either one or both to contain %keyword%

    please help me

    when i do
    WHERE type ='articles ' and subject like '%".keyword."%' and content like '%".keyword."%' ";

    it will return entries where type = article AND subject containing keyword AND content containing keyword

    which is different from what i want.
    i want to return type=article AND either content or subject containing keyword

    please
    help
    me

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,021
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    simple, just use parentheses
    Code:
     where type ='articles' 
       and (
           subject like '%keyword%' 
        or content like '%keyword%'
           )
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Guru defiance's Avatar
    Join Date
    Oct 2004
    Location
    United states
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh...


    thank you so much..



    thankz.


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
  •