Received: from hotmail.com (law-f172.hotmail.com [209.185.131.235]) by hub.org (8.10.1/8.10.1) with SMTP id e6G7pr050495 for ; Sun, 16 Jul 2000 03:51:53 -0400 (EDT) Received: (qmail 28823 invoked by uid 0); 16 Jul 2000 07:51:47 -0000 Message-ID: <20000716075147.28822.qmail@hotmail.com> Received: from 213.29.16.2 by www.hotmail.com with HTTP; Sun, 16 Jul 2000 00:51:47 PDT X-Originating-IP: [213.29.16.2] From: "omid omoomi" To: kumar1@home.com, pgsql-sql@postgresql.org Subject: Re: Select by priority Date: Sun, 16 Jul 2000 00:51:47 PDT Mime-Version: 1.0 Content-Type: text/plain; format=flowed X-Archive-Number: 200007/157 Hi, How about ordering by Address_type ? only needs to have 1, 2, 3 as different address types in your desired order. like : select person_id , address where address in not null order by address_type limit 1 ; sure you can change the limit if you wish more addresses. hope that helps Omid Omoomi >From: kumar1@home.com (Prasanth A. Kumar) >To: pgsql-sql@postgresql.org >Subject: [SQL] Select by priority >Date: 15 Jul 2000 10:11:43 -0700 > >I need some suggestions on how to construct a particular select that I >need. I have a table of addresses where the primary key is the >persons_id and a address_type field. The address_type field is a >character which specifies whether the address is for the home, work, >or mailing. A person can have multiple addresses though only one of a >type. What I want to do is select a list of address for each distinct >individual but wish to select based of priority that if the mailing >address exists, I get that one only. If there is no mailing address, I >want the home address and failing that, get the work address. Is it >within the realm of sql to be able to do that? > >-- >Prasanth Kumar >kumar1@home.com ________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com