SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Thread: except queries

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

    except queries

    Hi.

    can any1 of you help me out?

    i need to run this queries;

    select keyword, id from table where keyword like %keyword%, but i need to exclude some id.

    lets say i need to exculde id=3
    the queries would be

    select keyword, id from table where keyword like %keyword% exclude id = 3

    please help me...

    thank you so much!!!!

  2. #2
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe this...
    Code:
    SELECT
       keyword, id
    FROM
       table
    WHERE
       keyword
    LIKE 
       '%keyword%'
    AND
       id != 3
    Lats...

  3. #3
    SitePoint Enthusiast gesf's Avatar
    Join Date
    Oct 2004
    Location
    Portugal
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
      SELECT keyword, id 
         FROM table 
            WHERE keyword LIKE '%whatever%' 
            AND id <> 3

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


    can i have mulitple exception?

    like

    and id != 3 and id !=4 and id !=5?

    i believe there is another way to do it right/?

    thankz!

  5. #5
    SitePoint Enthusiast gesf's Avatar
    Join Date
    Oct 2004
    Location
    Portugal
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
       SELECT keyword, id 
          FROM table 
             WHERE keyword LIKE '%whatever%' 
             AND id <> 3
             OR id <> 4
             OR id <> 6
    That should work

  6. #6
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A bit neater...
    Code:
    SELECT
       keyword, id
    FROM
       table
    WHERE
       keyword
    LIKE 
       '%keyword%'
    AND
       id NOT IN(3,4,5)
    Lats...

  7. #7
    SitePoint Enthusiast gesf's Avatar
    Join Date
    Oct 2004
    Location
    Portugal
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I knew there was another and better way!
    Great Lats

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

    thank you everyone.


  9. #9
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,015
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    gesf, your query will return all rows in the table

    be careful when mixing ANDs and NOTs and ORs

    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •