Greg, GS> There's no efficient way to write this in standard SQL. GS> However Postgres has an extension DISTINCT ON that would GS> do it: Works as advertised - many thanks! I'd missed the DISTINCT ON extension... This really is a great list - you've saved me a couple of hours of agony, I suspect. ------------------ Geoff Caplan Vario Software Ltd (+44) 121-515 1154 ---------------------------(end of broadcast)--------------------------- TIP 4: Don't 'kill -9' the postmaster