Re: pull in most recent record in a view - Mailing list pgsql-sql

From Gary Stainburn
Subject Re: pull in most recent record in a view
Date
Msg-id 201210261024.40026.gary.stainburn@ringways.co.uk
Whole thread Raw
In response to pull in most recent record in a view  (Gary Stainburn <gary.stainburn@ringways.co.uk>)
Responses Re: pull in most recent record in a view
List 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 



pgsql-sql by date:

Previous
From: Gary Stainburn
Date:
Subject: pull in most recent record in a view
Next
From: David Johnston
Date:
Subject: Re: pull in most recent record in a view