X-Original-To: pgsql-sql@postgresql.org Received: from rtlocal.trade-india.com (mail-relay.trade-india.com [203.196.129.235]) by postgresql.org (Postfix) with SMTP id 495D04760CC for ; Fri, 7 Mar 2003 02:53:35 -0500 (EST) Received: (qmail 425 invoked from network); 7 Mar 2003 07:52:56 -0000 Received: from unknown (HELO system67.trade-india-local.com) (192.168.0.67) by infocom-236-129-del.trade-india.com with SMTP; 7 Mar 2003 07:52:56 -0000 From: Rajesh Kumar Mallah Organization: Infocom Network Limited To: Stephan Szabo Subject: Re: sql question regarding count(*) Date: Fri, 7 Mar 2003 13:25:26 +0530 User-Agent: KMail/1.5 Cc: Tomasz Myrta , References: <20030306223558.A87666-100000@megazone23.bigpanda.com> In-Reply-To: <20030306223558.A87666-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200303071325.26899.mallah@trade-india.com> X-Archive-Number: 200303/178 X-Sequence-Number: 12218 i will think more abt this issue and will discuss. regds mallah. On Friday 07 March 2003 12:10 pm, Stephan Szabo wrote: > On Fri, 7 Mar 2003, Rajesh Kumar Mallah wrote: > > On Friday 07 March 2003 11:41 am, Stephan Szabo wrote: > > > On Fri, 7 Mar 2003, Rajesh Kumar Mallah wrote: > > > > Tomasz did you notice the two queries are totally differet on > > > > different tables? > > > > > > A count() on a non-grouped table returns 1 row. > > > > > > A grouped table returns 1 row per group. If there are no groups, no > > > rows are returned. If the groups are filtered by a having clause, it > > > might also return no rows. > > > > True the second query does not return any row. > > even in first case no rows are returned. > > > > where is the difference? > > I don't think I understand the question. > > select userid from users where userid=-1 > returns 1 row for each row the where clause returns true > and 0 rows if there are none. > > select count(*) from users where userid=-1 > returns 1 row (it's not a grouped table) > > select count(*) from users where userid=-1 group by userid > returns 1 row if there is at least 1 row having userid=-1 > or 0 rows otherwise (either there is a group or there isn't) > > select count(*) from users where userid=-1 group by userid > having userid!=-1 > should return 0 rows because even if there is a group it'll fail the > having clause. > > > ---------------------------(end of broadcast)--------------------------- > TIP 3: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly -- Regds Mallah ---------------------------------------- Rajesh Kumar Mallah, Project Manager (Development) Infocom Network Limited, New Delhi phone: +91(11)6152172 (221) (L) ,9811255597 (M) Visit http://www.trade-india.com , India's Leading B2B eMarketplace.