Re: select tbl1.attr1, number of tuples where tbl2.attr1=tbl1.attr1 - Mailing list pgsql-sql

From Tom Lane
Subject Re: select tbl1.attr1, number of tuples where tbl2.attr1=tbl1.attr1
Date
Msg-id 3360.993218067@sss.pgh.pa.us
Whole thread Raw
In response to select tbl1.attr1, number of tuples where tbl2.attr1=tbl1.attr1  ("Markus Bertheau" <twanger@eudoramail.com>)
List pgsql-sql
"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
groupby 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


pgsql-sql by date:

Previous
From: "Ari Nepon"
Date:
Subject: RE: Help with a double left join
Next
From: Alex Pilosov
Date:
Subject: Re: Help with a double left join