I have a table that contains a list of names used to designate objects (represented themselves by an id). It is created with:
CREATE TABLE all_names
(
id integer NOT NULL,
name varchar(64) PRIMARY KEY,
priority integer NOT NULL,
);
(The priority field is mostly used to sort the list of synonyms of an object with given id.)
I would like to create from this table another table that associates to each object its name with highest priority. Columns should be like this:
CREATE TABLE objs
(
id integer PRIMARY KEY,
name varchar(64) NOT NULL UNIQUE,
);
How can I fill the new table with only the top names?
Example
all_names:
id name priority
----------------
1 A 3
1 AA 2
1 AAA 1
2 B 1
3 C 4
3 CC 3
3 CCC 2
3 CCCC 1
should give me:
objs:
id name
-------
1 A
2 B
3 C
as the name of object 1 with highest priority is A, etc.
EDIT