pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedsql question regarding count(*)
7+ messages / 3 participants
[nested] [flat]
* sql question regarding count(*)
@ 2003-03-06 11:32 Rajesh Kumar Mallah <mallah@trade-india.com>
2003-03-06 12:00 ` Re: sql question regarding count(*) Tomasz Myrta <jasiek@klaster.net>
0 siblings, 1 reply; 7+ messages in thread
From: Rajesh Kumar Mallah @ 2003-03-06 11:32 UTC (permalink / raw)
To: pgsql-sql
When does count(*) returns "o rows" ?
and when does it return 1 row value being 0.
tradein_clients=# SELECT count(*) from public.eyp_listing where sno> 0 and
amount> 0 group by sno,branch,edition having count(distinct userid) > 1 ;
count
-------
(0 rows)
tradein_clients=#
tradein_clients=#
tradein_clients=# SELECT count(*) from public.users where userid=-1;
count
-------
0
(1 row)
tradein_clients=#
--
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.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: sql question regarding count(*)
2003-03-06 11:32 sql question regarding count(*) Rajesh Kumar Mallah <mallah@trade-india.com>
@ 2003-03-06 12:00 ` Tomasz Myrta <jasiek@klaster.net>
2003-03-07 05:23 ` Re: sql question regarding count(*) Rajesh Kumar Mallah <mallah@trade-india.com>
0 siblings, 1 reply; 7+ messages in thread
From: Tomasz Myrta @ 2003-03-06 12:00 UTC (permalink / raw)
To: Rajesh Kumar Mallah <mallah@trade-india.com>; +Cc: pgsql-sql
Rajesh Kumar Mallah wrote:
> When does count(*) returns "o rows" ?
> and when does it return 1 row value being 0.
>
> tradein_clients=# SELECT count(*) from public.eyp_listing where sno> 0 and
> amount> 0 group by sno,branch,edition having count(distinct userid) > 1 ;
> count
> -------
> (0 rows)
>
> tradein_clients=#
> tradein_clients=#
> tradein_clients=# SELECT count(*) from public.users where userid=-1;
> count
> -------
> 0
> (1 row)
>
> tradein_clients=#
It's because of your having clause.
If count(*)=0 then having count(*)>1 results in no rows.
Regards,
Tomasz Myrta
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: sql question regarding count(*)
2003-03-06 11:32 sql question regarding count(*) Rajesh Kumar Mallah <mallah@trade-india.com>
2003-03-06 12:00 ` Re: sql question regarding count(*) Tomasz Myrta <jasiek@klaster.net>
@ 2003-03-07 05:23 ` Rajesh Kumar Mallah <mallah@trade-india.com>
2003-03-07 06:11 ` Re: sql question regarding count(*) Stephan Szabo <sszabo@megazone23.bigpanda.com>
0 siblings, 1 reply; 7+ messages in thread
From: Rajesh Kumar Mallah @ 2003-03-07 05:23 UTC (permalink / raw)
To: Tomasz Myrta <jasiek@klaster.net>; +Cc: pgsql-sql
Tomasz did you notice the two queries are totally differet on different
tables?
On Thursday 06 March 2003 05:30 pm, Tomasz Myrta wrote:
> Rajesh Kumar Mallah wrote:
> > When does count(*) returns "o rows" ?
> > and when does it return 1 row value being 0.
> >
> > tradein_clients=# SELECT count(*) from public.eyp_listing where sno> 0
> > and amount> 0 group by sno,branch,edition having count(distinct userid)
> > > 1 ; count
> > -------
> > (0 rows)
> >
> > tradein_clients=#
> > tradein_clients=#
> > tradein_clients=# SELECT count(*) from public.users where userid=-1;
> > count
> > -------
> > 0
> > (1 row)
> >
> > tradein_clients=#
>
> It's because of your having clause.
> If count(*)=0 then having count(*)>1 results in no rows.
>
> Regards,
> Tomasz Myrta
--
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.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: sql question regarding count(*)
2003-03-06 11:32 sql question regarding count(*) Rajesh Kumar Mallah <mallah@trade-india.com>
2003-03-06 12:00 ` Re: sql question regarding count(*) Tomasz Myrta <jasiek@klaster.net>
2003-03-07 05:23 ` Re: sql question regarding count(*) Rajesh Kumar Mallah <mallah@trade-india.com>
@ 2003-03-07 06:11 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
2003-03-07 06:31 ` Re: sql question regarding count(*) Rajesh Kumar Mallah <mallah@trade-india.com>
0 siblings, 1 reply; 7+ messages in thread
From: Stephan Szabo @ 2003-03-07 06:11 UTC (permalink / raw)
To: Rajesh Kumar Mallah <mallah@trade-india.com>; +Cc: Tomasz Myrta <jasiek@klaster.net>; pgsql-sql
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.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: sql question regarding count(*)
2003-03-06 11:32 sql question regarding count(*) Rajesh Kumar Mallah <mallah@trade-india.com>
2003-03-06 12:00 ` Re: sql question regarding count(*) Tomasz Myrta <jasiek@klaster.net>
2003-03-07 05:23 ` Re: sql question regarding count(*) Rajesh Kumar Mallah <mallah@trade-india.com>
2003-03-07 06:11 ` Re: sql question regarding count(*) Stephan Szabo <sszabo@megazone23.bigpanda.com>
@ 2003-03-07 06:31 ` Rajesh Kumar Mallah <mallah@trade-india.com>
2003-03-07 06:40 ` Re: sql question regarding count(*) Stephan Szabo <sszabo@megazone23.bigpanda.com>
0 siblings, 1 reply; 7+ messages in thread
From: Rajesh Kumar Mallah @ 2003-03-07 06:31 UTC (permalink / raw)
To: Stephan Szabo <sszabo@megazone23.bigpanda.com>; +Cc: Tomasz Myrta <jasiek@klaster.net>; pgsql-sql
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?
tradein_clients=# select userid from users where userid=-1;
+--------+
| userid |
+--------+
+--------+
(0 rows)
Time: 846.86 ms
tradein_clients=#
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.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: sql question regarding count(*)
2003-03-06 11:32 sql question regarding count(*) Rajesh Kumar Mallah <mallah@trade-india.com>
2003-03-06 12:00 ` Re: sql question regarding count(*) Tomasz Myrta <jasiek@klaster.net>
2003-03-07 05:23 ` Re: sql question regarding count(*) Rajesh Kumar Mallah <mallah@trade-india.com>
2003-03-07 06:11 ` Re: sql question regarding count(*) Stephan Szabo <sszabo@megazone23.bigpanda.com>
2003-03-07 06:31 ` Re: sql question regarding count(*) Rajesh Kumar Mallah <mallah@trade-india.com>
@ 2003-03-07 06:40 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
2003-03-07 07:55 ` Re: sql question regarding count(*) Rajesh Kumar Mallah <mallah@trade-india.com>
0 siblings, 1 reply; 7+ messages in thread
From: Stephan Szabo @ 2003-03-07 06:40 UTC (permalink / raw)
To: Rajesh Kumar Mallah <mallah@trade-india.com>; +Cc: Tomasz Myrta <jasiek@klaster.net>; pgsql-sql
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.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: sql question regarding count(*)
2003-03-06 11:32 sql question regarding count(*) Rajesh Kumar Mallah <mallah@trade-india.com>
2003-03-06 12:00 ` Re: sql question regarding count(*) Tomasz Myrta <jasiek@klaster.net>
2003-03-07 05:23 ` Re: sql question regarding count(*) Rajesh Kumar Mallah <mallah@trade-india.com>
2003-03-07 06:11 ` Re: sql question regarding count(*) Stephan Szabo <sszabo@megazone23.bigpanda.com>
2003-03-07 06:31 ` Re: sql question regarding count(*) Rajesh Kumar Mallah <mallah@trade-india.com>
2003-03-07 06:40 ` Re: sql question regarding count(*) Stephan Szabo <sszabo@megazone23.bigpanda.com>
@ 2003-03-07 07:55 ` Rajesh Kumar Mallah <mallah@trade-india.com>
0 siblings, 0 replies; 7+ messages in thread
From: Rajesh Kumar Mallah @ 2003-03-07 07:55 UTC (permalink / raw)
To: Stephan Szabo <sszabo@megazone23.bigpanda.com>; +Cc: Tomasz Myrta <jasiek@klaster.net>; pgsql-sql
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.
^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2003-03-07 07:55 UTC | newest]
Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-03-06 11:32 sql question regarding count(*) Rajesh Kumar Mallah <mallah@trade-india.com>
2003-03-06 12:00 ` Tomasz Myrta <jasiek@klaster.net>
2003-03-07 05:23 ` Rajesh Kumar Mallah <mallah@trade-india.com>
2003-03-07 06:11 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
2003-03-07 06:31 ` Rajesh Kumar Mallah <mallah@trade-india.com>
2003-03-07 06:40 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
2003-03-07 07:55 ` Rajesh Kumar Mallah <mallah@trade-india.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox