Re: Is there a more elegant way to write this query?...

From: "Nick Fankhauser" <nickf(at)ontko(dot)com>
To: "Eric Soroos" <eric-psql(at)soroos(dot)net>
Cc: "PGSQL-SQL" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Is there a more elegant way to write this query?...
Date: 2003-11-11 21:23:02
Message-ID: NEBBLAAHGLEEPCGOBHDGCEFPJGAA.nickf@ontko.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi Eric-

Thanks for your suggestion.

> An explain analyze would help.

I'll do that (and move the question to the performance list) when I get to
the performance question, but at this point, I'm just seeking some help in
looking at this from a different angle- I couldn't figure out how to achieve
the result I was after without using max(), which felt like a kludge. Your
solution gave me the start I needed.

-Nick

> How about:
> select
> actor.actor_full_name,
> actor.actor_id,
> s1.ctCases,
> s1.case_id,
> case_data.case_public_id
> from
> actor inner join ( select actor_id, count(*) as ctCases,
> max(case_id)
> as case_id
> from
> actor_case_assignment group by actor_id) as s1
> on (actor.actor_id = s1.actor_id)
> left outer join case_data using
> (s1.case_id=case_data.case_id)
> limit 1000;

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Troels Arvin 2003-11-11 22:58:09 Quota query with decent performance?
Previous Message Rajesh Kumar Mallah 2003-11-11 19:20:14 Re: transaction processing after error in statement