SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict tempyyyst's Avatar
    Join Date
    Nov 2001
    Location
    Kent, UK
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    excluding a particular record from a results set

    Hello all

    I have a query that retrieves a set of company data:

    Code:
    SELECT DISTINCT company, url, info, logosmall FROM company LEFT JOIN award_ceremony ON award_ceremony.sponsor=company.id WHERE award_ceremony.ceremony_id=8 ORDER BY company
    What I want to do is exclude a particular company by id, so I tried...

    Code:
    SELECT DISTINCT company.id, company, url, info, logosmall FROM company LEFT JOIN award_ceremony ON award_ceremony.sponsor=company.id WHERE award_ceremony.ceremony_id=$currentid WHERE company.id NOT 5 ORDER BY company
    Which to not much surprise on my part just caused an error.

    Do I do this with a WHERE statement, in which case where does it go and what's the syntax?

    Thanks in advance for any help.

  2. #2
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Code:
    SELECT DISTINCT company.id, company, url, info, logosmall FROM company
    LEFT JOIN award_ceremony ON award_ceremony.sponsor=company.id
    WHERE award_ceremony.ceremony_id={$currentid}
    	AND company.id <> 5
    ORDER BY company
    Try that, it should work for you

  3. #3
    SitePoint Addict tempyyyst's Avatar
    Join Date
    Nov 2001
    Location
    Kent, UK
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks,

    What if I want to exclude more than 1 id?

    Code:
     AND company.id <> 5,1
    ???

  4. #4
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can do something like this:
    Code:
    AND company.id NOT IN (5, 1, 23)


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
  •