Re: 'not in' and 'not exist'
From: Learner (wantnospam_at_email.com)
Date: 03/27/04
- Next message: Greg Linwood: "Re: Trigger invoking VB passing parameters"
- Previous message: Eria Tlov: "RE: Getting Data From Exchange"
- Next in thread: Steve Kass: "Re: 'not in' and 'not exist'"
- Reply: Steve Kass: "Re: 'not in' and 'not exist'"
- Maybe reply: Joe Celko: "Re: 'not in' and 'not exist'"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 27 Mar 2004 15:50:07 +0500
Hi,
Given the scenario that you have mentioned wouldn't the following query
return the same results? Sorry if this sounds silly but your reply will
help me improve my concepts and understanding:
Your suggestion:
> SELECT * FROM complaints c
> WHERE NOT EXISTS
> (SELECT * FROM orders o
> WHERE o.orderDate = c.complaintDate
> AND o.customerID = c.customerID)
Can this also do the same job:
Select * from complaints
Where complaints.orderid = orders.orderid
AND complaints.complaintDate <> orders.orderDate
I'll appreciate your reply and feedback.
Thanks.
> Let's say you have two tables: orders and complaints
>
> each table has a customerID and a date column (which stores just the date at
> midnight).
>
> Now say you wanted to find out the customers who complained, but NOT on the
> same day they placed an order. (And hey, ease up, I'm coming up with this
> fictional crap on the fly. :-))
>
> You can say:
>
> SELECT * FROM complaints c
> WHERE NOT EXISTS
> (SELECT * FROM orders o
> WHERE o.orderDate = c.complaintDate
> AND o.customerID = c.customerID)
>
> You can't say:
>
> SELECT * FROM complaints c
> WHERE customerID and complaintDate
> NOT IN (SELECT customerID, orderDate FROM orders)
>
> You could do it quasi-reliably if you converted both columns, in the
> predicate and the sub-query, and joined them as a single varchar. But you
> would throw performance out the window due to scans.
>
>
- Next message: Greg Linwood: "Re: Trigger invoking VB passing parameters"
- Previous message: Eria Tlov: "RE: Getting Data From Exchange"
- Next in thread: Steve Kass: "Re: 'not in' and 'not exist'"
- Reply: Steve Kass: "Re: 'not in' and 'not exist'"
- Maybe reply: Joe Celko: "Re: 'not in' and 'not exist'"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|