Skip site navigation (1) Skip section navigation (2)

Select by priority

From: kumar1(at)home(dot)com (Prasanth A(dot) Kumar)
To: pgsql-sql(at)postgresql(dot)org
Subject: Select by priority
Date: 2000-07-15 17:11:43
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-sql
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


pgsql-sql by date

Next:From: omid omoomiDate: 2000-07-16 00:51:47
Subject: Re: Select by priority
Previous:From: Tom LaneDate: 2000-07-15 15:59:42
Subject: Re: Applying SUM twice in the same query.

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group