From: Gary J. Farmer <farmer@arlut.utexas.edu>
To: pgsql-sql@postgresql.org
Subject: RE: Select by priority
Date: Mon, 17 Jul 2000 17:12:54 -0500
Message-ID: <NDBBKNPOIKAFAGAOPAPNCEMCCBAA.farmer@arlut.utexas.edu> (raw)
In-Reply-To: <m3og3ycwyl.fsf@C654771-a.frmt1.sfba.home.com>
>> I think the order thing will work though I have no choice of using
>> numbering for the address_type as I am working off a pre-existing
>> database. They are using a mnemonic char type. I am essentially batch
>> downloading and processing this and other database tables for query
>> and presentations using web pages. BTW, does the 'limit' feature exist
>> in Oracle? The main database I am extracting data from is Oracle...
I do not know whether you can add a table associating "priority" with
"address_type". If you can, you might try something like the following
example, using the address_priority table:
create table address_table (
person_id integer,
address_type varchar(1),
address varchar(50)
);
insert into address_table values ( 1, 'W', 'ROUTE 1, WORK ST');
insert into address_table values ( 2, 'H', 'ROUTE 2, HOME AVE');
insert into address_table values ( 3, 'W', 'ROUTE 3, WORK ST');
insert into address_table values ( 3, 'H', 'ROUTE 3, HOME AVE');
insert into address_table values ( 4, 'M', 'ROUTE 4, MAIL RD');
insert into address_table values ( 5, 'M', 'ROUTE 5, MAIL RD');
insert into address_table values ( 5, 'W', 'ROUTE 5, WORK ST');
insert into address_table values ( 6, 'M', 'ROUTE 6, MAIL RD');
insert into address_table values ( 6, 'H', 'ROUTE 6, HOME AVE');
insert into address_table values ( 7, 'M', 'ROUTE 7, MAIL RD');
insert into address_table values ( 7, 'H', 'ROUTE 7, HOME AVE');
insert into address_table values ( 7, 'W', 'ROUTE 7, WORK ST');
create table address_priority (
address_type varchar(1),
priority integer
);
insert into address_priority values ( 'M', 1 );
insert into address_priority values ( 'H', 2 );
insert into address_priority values ( 'W', 3 );
select person_id, address
from address_table a, address_priority b
where
(person_id, priority) in
(select person_id, min(priority)
from address_table a, address_priority b
where a.address_type = b.address_type
group by person_id) and
a.address_type = b.address_type;
PERSON_ID ADDRESS
---------- --------------------------------------------------
1 ROUTE 1, WORK ST
2 ROUTE 2, HOME AVE
3 ROUTE 3, HOME AVE
4 ROUTE 4, MAIL RD
5 ROUTE 5, MAIL RD
6 ROUTE 6, MAIL RD
7 ROUTE 7, MAIL RD
Appears to work with either Oracle or Postgres (though I changed VARCHAR
to VARCHAR2 for Oracle).
Gary Farmer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: farmer@arlut.utexas.edu
Subject: Re: Select by priority
In-Reply-To: <NDBBKNPOIKAFAGAOPAPNCEMCCBAA.farmer@arlut.utexas.edu>
References: <m3og3ycwyl.fsf@C654771-a.frmt1.sfba.home.com> <NDBBKNPOIKAFAGAOPAPNCEMCCBAA.farmer@arlut.utexas.edu>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox