Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 08B089F979B for ; Wed, 15 Aug 2007 17:58:18 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 11510-05 for ; Wed, 15 Aug 2007 17:58:10 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from pyxis.powervt.com.ar (host3.powervt.com.ar [200.43.63.66]) by postgresql.org (Postfix) with ESMTP id 7BA229F97C1 for ; Wed, 15 Aug 2007 17:58:13 -0300 (ADT) Received: from pcfhevia ([201.216.249.98]) by pyxis.powervt.com.ar (IPGroup Mail Server) with ESMTP id 1OT48953; Wed, 15 Aug 2007 17:58:11 -0300 From: "Fernando Hevia" To: "'Mike Diehl'" , "'SQL Postgresql List'" Subject: Re: Problem with phone list. Date: Wed, 15 Aug 2007 17:58:22 -0300 Organization: IP-TEL Message-ID: <021801c7df7f$043d8610$8f01010a@iptel.com.ar> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook 11 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138 In-Reply-To: <200708151428.17740.jdiehl@sandia.gov> Thread-Index: AcfffSDyKIcizsrZTta2DOCXcUxf+AAAIiew X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/134 X-Sequence-Number: 29072 Try this: Select * from view v1 where duration =3D (select max(duration) from view v2 where = v2.phone_number =3D v1.phone_number) You could get more than one call listed for the same number if many = calls match max(duration) for that number. -----Mensaje original----- De: pgsql-sql-owner@postgresql.org = [mailto:pgsql-sql-owner@postgresql.org] En nombre de Mike Diehl Enviado el: Mi=E9rcoles, 15 de Agosto de 2007 17:28 Para: SQL Postgresql List Asunto: [SQL] Problem with phone list. Hi all. I've qot a problem I need to solve. I'm sure it's pretty simple; I just can't=20 seem to get it, so here goes... I've got a table, actually a view that joins 3 tables, that contains a = phone number, a unique id, and a call duration. The phone number has duplicates in it but the unique id is unique. I need to get a list of distinct phone numbers and the coorisponding = largest call duration. I've got the idea that this should be a self-join on phone number where=20 a.id<>b.id, but I just can't seem to get the max duration. Any hints would be much appreciated. Mike. ---------------------------(end of broadcast)--------------------------- TIP 4: Have you searched our list archives? http://archives.postgresql.org