Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: A query that uses not equals
twitched_at_msn.com (Cherron) wrote in
news:bd72678d.0210271036.41af0fe2_at_posting.google.com:
> I have a customer table
>
> cus_code PK
> cus_balance
>
> and a invoice table
>
> cus_code FK
> inv_number
> inv_date
> invo_items
>
> I need to be able to select the customers that did not make purchases
> on 8/18/1999 and 8/19/1999
>
> The code that I came up which is listed below does not work because
> the syntax is wrong and I gues the logic as well.
>
> SELECT CUSTOMER.CUS_CODE, CUSTOMER.CUS_BALANCE
> FROM CUSTOMER, INVOICE
> WHERE INVOICE.INV_DATE != "08/18/1999" OR INVOICE.INV_DATE != "
> 08/19/1999"
> ORDER BY CUSTOMER.CUS_CODE;
>
> Can anyone tell me what I am doing wrong? I would appreciate your
> help.
>
> Thanks
What's wrong with this? Everything. First off *never* use "or" with != conditions. A!=1 or A!=2 is always true, even when A=1 or A=2. If A=1 it's still !=2 so the condition is still true. Second. What Jim Kennedy said about the dates. Third. You're not joining customer with invoice anywhere. This query would result in selecting every customer multiple times (as many times as there are invoices that matched the date condition, if the date condition were stated correctly).
Are you a student? If you're not I think it's very distressing that I can't find a job and there are people as unknowledgeable as you out there working. Anyway, I'm going on the assumption that you're a student and I'm not going to do your homework for you. I'll just give you a hint. You'll have to use "not exists".
-- Ken Denny http://www.kendenny.com/Received on Thu Nov 21 2002 - 08:43:32 CST
![]() |
![]() |