Page 1 of 1

ARRAYS OR SQL UNION?

Posted: Fri Feb 25, 2011 10:48 am
by pgdesign
Hi,
I have an issue that I can't get my head around and solve:

I'll use a clean example below that relates to my problem. I have a table like

plan | title | cost
------------------------
n1 | aa | 0.02
n1 | bb | 0.02
n2 | aa | 0.01
n2 | bb | 0.01
n2 | cc | 0.01

What I need to do is output all unique titles with the cost against them (title - cost).

In the example, there are three unique titles, two of these are on two different plans.

Now I can't order these by cost. What I need to do is search 'titles' on plan 'n1' and display that price, then if there are any other plans, in this case 'n2' that have a title not in n1, display that.

I would expect a result like:
aa - 0.02
bb - 0.02
cc - 0.01

It sounds simple but it's not for me. I can't create any temp tables, it has to be through the sql or fetching the arrays and sorting them there.

Any help would be much appreciated!