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

Home -> Community -> Usenet -> c.d.o.misc -> Re: Query Help

Re: Query Help

From: <cnbland1_at_juno.com>
Date: Fri, 21 Dec 2007 13:11:35 -0800 (PST)
Message-ID: <5fd3421e-3f69-4365-ace0-b33a52f18a56@d21g2000prf.googlegroups.com>


On Dec 21, 2:06 pm, Charles Hooper <hooperc2..._at_yahoo.com> wrote:
> On Dec 21, 12:48 pm, cnbla..._at_juno.com wrote:
>
>
>
>
>
> > I am a beginning Oracle 9i user and I was hoping that someone can help
> > me. I think I have the basic SQL statements down pat, but this
> > problem is a little too advanced for me.
>
> > Let's say that I have Table A with the following columns: Food_ID,
> > Descr, Cat_ID and Status. Here are some sample rows in the table:
> > 301 Apple 10 Active
> > 301 Ham 20 Inactive
> > 301 Carrot 30 Active
> > 302 Orange 10 Inactive
> > 302 Balony 20 Active
>
> > I would like to find all instances where the Food_ID does not have a
> > Cat_ID of 30 or has a Cat_ID of 30, but it is Inactive. In the example
> > shown above, I would see Food_ID of 302, but not 301.
>
> > Thank you,
>
> If you are famailar with BASIC programming, a similar construct might
> look like this:
> IF (AGE <> 65) OR (AGE = 65 AND RETIRED = "Y") THEN
>
> The WHERE clause syntax in Oracle is similar to the above, if you omit
> the "IF" and the "THEN", and replace the double quotes with single
> quotes. All that you would then need to do is substitute your column
> names and the values that you are checking.
>
> Charles Hooper
> IT Manager/Oracle DBA
> K&M Machine-Fabricating, Inc.- Hide quoted text -
>
> - Show quoted text -

From what you have suggested, I would run something like the following:
Select Distinct Food_ID
From Table A
Where (Cat_ID <> 30) OR (Cat_ID = 200 AND Status = 'I')

If I run the query that you suggest, wouldn't I see Food_ID 302 because there is one row for cat_ID 10 and another for 20? I only want to see a result of 302. Thank you for your help and patience. Received on Fri Dec 21 2007 - 15:11:35 CST

Original text of this message

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