Received: from C654771-a.frmt1.sfba.home.com (IDENT:root@c654771-a.frmt1.sfba.home.com [24.1.65.243]) by hub.org (8.10.1/8.10.1) with ESMTP id e6FHBi081017 for ; Sat, 15 Jul 2000 13:11:44 -0400 (EDT) Received: (from kumar1@localhost) by C654771-a.frmt1.sfba.home.com (8.9.3/8.9.3) id KAA05693; Sat, 15 Jul 2000 10:11:43 -0700 To: pgsql-sql@postgresql.org Subject: Select by priority From: kumar1@home.com (Prasanth A. Kumar) Date: 15 Jul 2000 10:11:43 -0700 Message-ID: Lines: 15 X-Mailer: Gnus v5.7/Emacs 20.7 X-Archive-Number: 200007/156 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