Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.tools -> SQL problem finding rows in same table

SQL problem finding rows in same table

From: DazedNConfused <nospamthanks_at_coldmail.com>
Date: Fri, 03 Nov 2000 17:37:36 GMT
Message-ID: <AJCM5.13707$rl.1150876@newsread2.prod.itd.earthlink.net>

I have a table "fruit" like this:
 ORDERNUM BOXNUM ITEM
--------- --------- ------

        1         1 apple
        1         1 orange
        1         2 apple
        1         2 grape
        2         1 apple
        2         1 orange
        2         1 grape
        3         1 apple

Each ordernum and boxnum can only have one of each item type.

I want to find boxes with both apples and oranges, so I do:

select apple.* from fruit apple, fruit orange where apple.item='apple' and orange.item='orange' and apple.ordernum=orange.ordernum
and apple.boxnum=orange.boxnum;

And I get what I expect:

  ORDERNUM BOXNUM ITEM
--------- --------- -------

        1         1 apple
        2         1 apple

As I add data, I some times get results like:

  ORDERNUM BOXNUM ITEM
--------- --------- -------

        1         1 apple
        1         1 apple
        1         1 apple
        2         1 apple
        2         1 apple
        2         1 apple

But there is only one "apple" and one "orange" in ordernum=1, boxnum=1

Why do I get duplicate results from my query some times?

Thank you Received on Fri Nov 03 2000 - 11:37:36 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US