pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedselect tbl1.attr1, number of tuples where tbl2.attr1=tbl1.attr1
2+ messages / 2 participants
[nested] [flat]
* select tbl1.attr1, number of tuples where tbl2.attr1=tbl1.attr1
@ 2001-06-22 12:06 Markus Bertheau <twanger@eudoramail.com>
2001-06-22 13:54 ` Re: select tbl1.attr1, number of tuples where tbl2.attr1=tbl1.attr1 Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 2+ messages in thread
From: Markus Bertheau @ 2001-06-22 12:06 UTC (permalink / raw)
To: pgsql-sql; +Cc: bertheau@bab24.de
Hey,
I have three tables.
table persons
{
login,
person_id UNIQUE
}
table views
{
person_id,
timestamp
}
table partners
{
person_id UNIQUE,
domain
}
for each tuple in partners i want to know the number of tuples in views with the same person_id.
I tried sth like
select partners.person_id, count(views.person_id) from partners, views where views.person_id = partners.person_id
but it said, partners.person_id must be grouped.
Then i tried
select partners.person_id, count(views.person_id) from partners, views where views.person_id = partners.person_id group by views.person_id
but this gave very strange results which are definitely not what i wanted.
How can I do that?
TIA,
Markus Bertheau
Cenes Data GmbH
Join 18 million Eudora users by signing up for a free Eudora Web-Mail account at http://www.eudoramail.com
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: select tbl1.attr1, number of tuples where tbl2.attr1=tbl1.attr1
2001-06-22 12:06 select tbl1.attr1, number of tuples where tbl2.attr1=tbl1.attr1 Markus Bertheau <twanger@eudoramail.com>
@ 2001-06-22 13:54 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2001-06-22 13:54 UTC (permalink / raw)
To: twanger@eudoramail.com; +Cc: pgsql-sql; bertheau@bab24.de
"Markus Bertheau" <twanger@eudoramail.com> writes:
> Then i tried
> select partners.person_id, count(views.person_id) from partners, views where views.person_id = partners.person_id group by views.person_id
> but this gave very strange results which are definitely not what i wanted.
I think you mistyped, because that query will also fail:
regression=# create table views (person_id int, timestamp timestamp);
CREATE
regression=# create table partners (person_id int UNIQUE, domain text);
NOTICE: CREATE TABLE/UNIQUE will create implicit index 'partners_person_id_key' for table 'partners'
CREATE
regression=# select partners.person_id, count(views.person_id)
regression-# from partners, views where views.person_id = partners.person_id
regression-# group by views.person_id;
ERROR: Attribute partners.person_id must be GROUPed or used in an aggregate function
How about showing us what you *really* did?
regards, tom lane
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2001-06-22 13:54 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-06-22 12:06 select tbl1.attr1, number of tuples where tbl2.attr1=tbl1.attr1 Markus Bertheau <twanger@eudoramail.com>
2001-06-22 13:54 ` Tom Lane <tgl@sss.pgh.pa.us>
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