select vs. select count - Mailing list pgsql-sql

From Claus Guttesen
Subject select vs. select count
Date
Msg-id b41c75520703270537y12d83fe5w7fc58f6e35fbe13d@mail.gmail.com
Whole thread Raw
Responses Re: select vs. select count
Re: select vs. select count
Re: select vs. select count
List pgsql-sql
Hi.

I'm performing the following query to get all items sold in 2006 which
are in category prints or gifts, but not in extra:

select order_id from(select o.order_id from orders o join order_lines ol using (order_id) where o.time >
'2006-01-01T00:00'and o.time < '2007-01-01T00:00' and (ol.item_id = 10 or ol.item_id = 11 or ol.item_id = 12) group by
 
o.order_id) as prints inner join(select ho.order_id from orders ho join order_lines hol using (order_id) where o.time >
'2006-01-01T00:00'and o.time < '2007-01-01T00:00' and (ol.item_id = 20 or ol.item_id = 21 or ol.item_id = 22) group by
 
o.order_id) as gifts using (order_id)except select order_id from (select ho.order_id from orders ho join order_lines
holusing (order_id)  where o.time > '2006-01-01T00:00' and o.time < '2007-01-01T00:00'  and (ol.item_id = 30 or
ol.item_id= 31 or ol.item_id = 32) group
 
by o.order_id) as extra;

When I do the 'select order_id' I get (after scrolling down):
order_id
---------
xyz
...
foo
bas
(1960 rows)

But when I do a 'select count(order_id) I get:
count
------- 2063

Why does select and select(count) produce two different results? Am I
doing something wrong here?

regards
Claus


pgsql-sql by date:

Previous
From: "Sabin Coanda"
Date:
Subject: array_to_string
Next
From: "Claus Guttesen"
Date:
Subject: Re: select vs. select count