Scott Ribe writes:
> Given that t2.id is the primary key, grouping by any other column of t2 is
> really redundant. I know *what* SQL won't allow me to do, I'm interested in
> knowing if there's some reason *why* other than historical...
SQL92 says so. More recent versions of the SQL spec descri
> -Original Message-
> From: pgsql-general-ow...@postgresql.org [mailto:pgsql-general-
> ow...@postgresql.org] On Behalf Of Scott Ribe
> Sent: Thursday, January 28, 2010 2:10 PM
> To: Thom Brown
> Cc: pgsql-general
> Subject: Re: [GENERAL] SQL question re aggregat
> You can't include an aggregate in the select if you don't group by
> non-aggregates, so it should be:
>
> select max(t1."When"), t1."Pt_Id", t2."DateOfBirth"
> from "PtStaffAccess" t1, "Person" t2
> where t1."Pt_Id" = t2.id
> group by t1."Pt_Id", t2."DateOfBirth";
I was aware that I could alter
On 28 January 2010 21:32, Scott Ribe wrote:
> OK, this does not work:
>
> select max(t1."When"), t1."Pt_Id", t2."DateOfBirth"
> from "PtStaffAccess" t1, "Person" t2
> where t1."Pt_Id" = t2.id
> group by t1."Pt_Id";
>
> But this does:
>
> select max(t1."When"), t1."Pt_Id", min(t2."DateOfBirth")
>
OK, this does not work:
select max(t1."When"), t1."Pt_Id", t2."DateOfBirth"
from "PtStaffAccess" t1, "Person" t2
where t1."Pt_Id" = t2.id
group by t1."Pt_Id";
But this does:
select max(t1."When"), t1."Pt_Id", min(t2."DateOfBirth")
from "PtStaffAccess" t1, "Person" t2
where t1."Pt_Id" = t2.id
gro