I have a table where I can have multiple names for a given id like this:
a_table (id int, name varchar(100), priority int);
I need a query that will search on names but make sure it will return only 1 name for each id, and that name will be the one with the higher priority.
e.g. if my data are
1, AaaB, 2 1, AbbB, 1 1, AccB, 0 2, foo, 0 3, AddC, 0
I want my query for "A%" to return:
1, AaaB 3, AddC
I was thinking something like:
select * from a_table where name like 'A%' group by id;
But this will not guarantee that the value with the higher priority will be selected.
Any ideas?