SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    It's been real... Forbes's Avatar
    Join Date
    Dec 2004
    Location
    Yorkshire, England
    Posts
    676
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Exclude row by ID?

    Hi guys!

    I'm trying to build a query that excludes specific rows by their ID, but I can't get it to work. Right now, I have:
    Code:
    AND (id <> '4151')
    Which I've tried with and without the single quotes. And in addition to which, I tried:
    Code:
    AND (id != '4151')
    Also, I've tried:
    Code:
    AND (id NOT IN (4151))
    And that didn't work either.

    Eventually, I'll need to be able to exclude several rows at a time.

    Yes, the core query works just fine.

    Yes, the ID column exists.

    Yes, the record also exists.

    Any ideas?

  2. #2
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When using the above examples do you get errors or are the id's simply not excluded?
    “Good artists copy, great artists steal” (Pablo Picasso - 1934)

  3. #3
    It's been real... Forbes's Avatar
    Join Date
    Dec 2004
    Location
    Yorkshire, England
    Posts
    676
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by donboe View Post
    When using the above examples do you get errors or are the id's simply not excluded?
    Hi! No, I don't get any errors; the row simply isn't excluded.

  4. #4
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Forbes View Post
    Hi! No, I don't get any errors; the row simply isn't excluded.
    Just tried your third option and it is working for me I only left the outside brackets out:
    Code MySQL:
    	WHERE id
      		NOT IN ( 13, 15 )
    “Good artists copy, great artists steal” (Pablo Picasso - 1934)

  5. #5
    It's been real... Forbes's Avatar
    Join Date
    Dec 2004
    Location
    Yorkshire, England
    Posts
    676
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by donboe View Post
    Just tried your third option and it is working for me I only left the outside brackets out...
    Which got me thinking about the brackets — I'd not placed earlier parts of the query in their own parentheses.

    I freely admit that databases aren't my strong point.

    All sorted now, guys.

    Thanks for your help!

  6. #6
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Forbes View Post
    I'd not placed earlier parts of the query in their own parentheses.
    Which is why you should post the entire query
    Glad you got your problem sorted out.

  7. #7
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good you have it sorted indeed! Have a happy new year
    “Good artists copy, great artists steal” (Pablo Picasso - 1934)


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
  •