Re: pull in most recent record in a view

From: Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: pull in most recent record in a view
Date: 2012-10-26 09:24:39
Message-ID: 201210261024.40026.gary.stainburn@ringways.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

This is my best effort so far is below. My concern is that it isn't very
efficient and will slow down as record numbers increase

create view current_qualifications as
select q.*, (q.qu_qualified+q.qu_renewal)::date as qu_expires from
qualifications q
join (select st_id, sk_id, max(qu_qualified) as qu_qualified from
qualifications group by st_id, sk_id) s
on q.st_id=s.st_id and q.sk_id = s.sk_id and q.qu_qualified = s.qu_qualified;

select t.st_id, t.st_name, k.sk_id, k.sk_desc, q.qu_qualified, q.qu_renewal,
q.qu_expires
from current_qualifications q
join staff t on t.st_id = q.st_id
join skills k on k.sk_id = q.sk_id;

--
Gary Stainburn
Group I.T. Manager
Ringways Garages
http://www.ringways.co.uk

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Mark Fenbers 2012-10-28 00:01:21 complex query
Previous Message Gary Stainburn 2012-10-26 09:02:01 pull in most recent record in a view