+ Reply to Thread
Results 1 to 4 of 4

Thread: SQL Help

  1. #1
    Join Date
    May 2002
    Posts
    29

    SQL Help

    I have three tables with their following attributes:

    INVOICE - rowstamp, ponumber, activitynumber, invoiceno
    PO - ponumber, postart, poend
    ACTIVITY - code

    PO, which has a list of Purchase Order Numbers; ACTIVITY, which has a list of Activities, and INVOICE, which matches activities to POs. Some Activities and POs are matched more than once - this is because there may be multiple invoices to the PO on the same activity; however, some POs are charged to more than one Activity, based on line items. Invoice number isn't really relevant to this query.

    ACTIVITY is joined to INVOICE on the activitynumber field. PO is joined to INVOICE on the ponumber field. There are no primary keys in any of the tables.

    What I'm trying to do is create a query between INVOICE, ACTIVITY, and PO that will list only those PO numbers (ponumber) that are associated with ALL codes (code) in the ACTIVITY table.

  2. #2
    Join Date
    Dec 2002
    Location
    Bangalore ( India )
    Posts
    2,434
    Code:
    Select PO.* 
    from INVOICE I, PO, ACTIVITY A 
    where I.ponumber        =    PO.ponumber       AND
          I.activitynumber  =    A.code            AND
          A.code            =    'ALL'
    ;
    Is this you want?

    Abhay.
    funky...

    "I Dont Want To Follow A Path, I would Rather Go Where There Is No Path And Leave A Trail."

    "Ego is the worst thing many have, try to overcome it & you will be the best, if not good, person on this earth"

  3. #3
    Join Date
    Jul 2001
    Location
    Slovenia
    Posts
    422
    Originally posted by abhaysk
    Code:
          A.code            =    'ALL'

    I like this approach. It's fast and simple.

    What about
    Code:
    select po.ponumber
      from po
     where not exists (select code from activity
                        minus
                       select activitynumber
                         from invoice i
                        where i.ponumber = po.ponumber)
    Tomaž
    "A common mistake that people make when trying to design something completely
    foolproof is to underestimate the ingenuity of complete fools" - Douglas Adams

  4. #4
    Join Date
    May 2002
    Posts
    29
    select po.ponumber
    from po
    where not exists (select code from activity
    minus
    select activitynumber
    from invoice i
    where i.ponumber = po.ponumber)
    -----

    That worked....

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
Click Here to Expand Forum to Full Width