SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict fattyjules's Avatar
    Join Date
    Dec 2005
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I write this query?

    I'm trying to put a query together, but my brain is failing me. Here's the simplified version of my schema;

    ORGANISATION
    id
    name

    NOTE
    id
    organisation_id
    category
    subcategory

    For a given organisation, I want to find the note category/subcategory combinations that the organisation DOESN'T have.

    For example, 'Smith Industries' might have notes about Pie/Baking, but no notes about Cheese/Disposal or Cheese/Production. So for 'Smith Industries', I want the output 'Cheese/Disposal' and 'Cheese/Production'.

    All note categories and subcategories are already known and defined, i.e. users can't invent them on the fly.
    Any help appreciated, this is confusing the hell out of me.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    you'll need a LEFT OUTER JOIN to match the categories/subcategories against the notes

    you say the categories/subcategories are already defined... where are they? which table?
    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
  •