From: | Peter Eisentraut <peter_e(at)gmx(dot)net> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Cc: | "Adam Rich" <adam(dot)r(at)sbcglobal(dot)net>, "'Scott Marlowe'" <smarlowe(at)g2switchworks(dot)com>, "'gustavo halperin'" <ggh(dot)develop(at)gmail(dot)com> |
Subject: | Re: postgresql vs mysql |
Date: | 2007-02-21 17:35:08 |
Message-ID: | 200702211835.08723.peter_e@gmx.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Adam Rich wrote:
> -- Query A
> select count(*) from customers c
> where not exists ( select 1 from orders o
> where o.customer_id = c.customer_id )
>
> -- Query B
> select count(*) from customers c
> where customer_id not in ( select customer_id from orders)
>
> -- Query C
> select count(*) from customers c
> left join orders o on c.customer_id = o.customer_id
> where o.order_id is null
>
> I believe they all achieve the same thing.
I think not. When using
INSERT INTO customers VALUES (1);
INSERT INTO customers VALUES (2);
INSERT INTO customers VALUES (NULL);
and
INSERT INTO orders VALUES (1);
INSERT INTO orders VALUES (3);
INSERT INTO orders VALUES (NULL);
I get
Query A: 2
Query B: 0
Query C: 3
--
Peter Eisentraut
http://developer.postgresql.org/~petere/
From | Date | Subject | |
---|---|---|---|
Next Message | Ian Harding | 2007-02-21 17:36:23 | Re: Recursive Left Joins Causing Trouble in 8.2.3 RESOLVED (kind of) |
Previous Message | Seb | 2007-02-21 17:20:38 | change data type int4 to serial |