Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id A9BA99FB5BD for ; Tue, 27 Mar 2007 09:38:18 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 38579-03 for ; Tue, 27 Mar 2007 09:37:53 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.170]) by postgresql.org (Postfix) with ESMTP id 0F9589FB53A for ; Tue, 27 Mar 2007 09:37:57 -0300 (ADT) Received: by ug-out-1314.google.com with SMTP id k3so1738323ugf for ; Tue, 27 Mar 2007 05:37:56 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=VSJPu0qtMGZb6dkOIxjpAFwrJAlGq+f7DrHfuFeQf5+cRmBASzHa6WxMBudIez7T5uktE6hjofbPo4TRCOTuQP53EGubELC3lzNYN1BpDciPOLfV5mnXACVgV1UUQrXL9L8hGILndE2oghaQtVcG3Xfbxgce/8Jr9yZAdu5C3R4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=AZTRSL/17NllTy3X7D6LJx5OfEIqFiUnOOD3WZrZmQ4zadiEUrewXOSyXwAYyEHaRd5QnWs6WdmiZVRX8EKqVlKY6MWM7LgFbCrVh/G0/2wl+KW0pWjHZ1oeNw4UD028ihmamR0r4eRvI0LMprSuRSQgNgEmGaof6gtMI+wgBFE= Received: by 10.115.54.1 with SMTP id g1mr3133943wak.1174999071251; Tue, 27 Mar 2007 05:37:51 -0700 (PDT) Received: by 10.114.194.12 with HTTP; Tue, 27 Mar 2007 05:37:51 -0700 (PDT) Message-ID: Date: Tue, 27 Mar 2007 14:37:51 +0200 From: "Claus Guttesen" To: pgsql-sql@postgresql.org Subject: select vs. select count MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200703/310 X-Sequence-Number: 27948 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 hol using (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