SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict hiddenpearls's Avatar
    Join Date
    Dec 2007
    Location
    Pakistan
    Posts
    262
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    NOT LIKE and AND/OR in MYSQL

    hello guys,

    I'm confused about AND/OR NOT LIKE in mysql query ..
    my query is like this

    select * from news_view WHERE collection_id = 18259 and ((news_headline NOT like '%Kim%' OR news_summary NOT like '%Kim%')) order by pub_date desc

    it returns the records that contains the word 'Kim' in news_summary though It shouldn't .. but when I use AND it returns results ok i.e it doesn't return the records that contains word 'Kim'

    I want to make it like this, if 'Kim' presents in both fields or in one of the fields it shouldn't appear ..

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by hiddenpearls View Post
    I want to make it like this, if 'Kim' presents in both fields or in one of the fields it shouldn't appear ..
    use AND
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Addict hiddenpearls's Avatar
    Join Date
    Dec 2007
    Location
    Pakistan
    Posts
    262
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    use AND
    confused when I used AND ... it shouldn't show when word is present in news_summary and not in news_headline ..

  4. #4
    SitePoint Addict hiddenpearls's Avatar
    Join Date
    Dec 2007
    Location
    Pakistan
    Posts
    262
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by hiddenpearls View Post
    confused when I used AND ... it shouldn't show when word is present in news_summary and not in news_headline ..
    Following works great btw,
    select * from news_view WHERE collection_id = 17743 AND NOT (news_headline like '%Kim%' OR news_summary like '%Kim%') order by pub_date desc

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    NOT (x OR y) is the same as NOT x AND NOT y
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  6. #6
    SitePoint Addict hiddenpearls's Avatar
    Join Date
    Dec 2007
    Location
    Pakistan
    Posts
    262
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    NOT (x OR y) is the same as NOT x AND NOT y
    oo Yes, you are right!


Tags for this Thread

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
  •