Hacker News new | ask | show | jobs
by lsb 4490 days ago
much inconsistent.

One nifty feature of Postgresql is that if you have a group by a,b,c,d, you need to aggregate everything else in your select that isn't a/b/c/d, or the statement won't prepare, whereas if you don't select an aggregate in MySQL you'll just get one random column, which is probably not what you want.

1 comments

This is mostly true, but in recent Postgres versions (since 9.1 I believe), if you GROUP BY the primary key, you can still include other columns in the SELECT statement. For instance:

    SELECT a.name, COUNT(b.id)
    FROM   a
    LEFT OUTER JOIN b ON b.a_id = a.id
    GROUP BY a.id
Pretty nice!