Re: ranked subqueries vs distinct question - Mailing list pgsql-general

From David McNett
Subject Re: ranked subqueries vs distinct question
Date
Msg-id 5292F47A-F488-4169-899F-35844C588489@macnugget.org
Whole thread Raw
In response to Re: ranked subqueries vs distinct question  (Karsten Hilbert <Karsten.Hilbert@gmx.net>)
Responses Re: ranked subqueries vs distinct question  (Karsten Hilbert <Karsten.Hilbert@gmx.net>)
List pgsql-general
On May 14, 2008, at 9:07 AM, Karsten Hilbert wrote:
> That doesn't work, unfortunately, because the urb (cities)
> table doesn't have the zip code. That's stored in a street
> table which foreign keys into the urb table. The
> dem.v_zip2data view aggregates streets, cities, states and
> countries for which there is a know linkage to a zip code at
> the street level. IOW, there are cities for which there is
> no known zip code. I want those to be matched, too, of
> course, courtesy of the user typing part of their name.

I think perhaps you have misunderstood what I was suggesting.  If the
SQL in your original post works, then my suggestion will also work.
In my haste to reply I accidentally omitted the where clause of the
query.

Wouldn't this (full example) work?

SELECT
   name,zip,
   (SELECT zip = '04317') as zipmatch
FROM
dem.urb
WHERE name ilike 'lei%'
ORDER BY zipmatch DESC, name;

If your code runs, this will too.

pgsql-general by date:

Previous
From: Karsten Hilbert
Date:
Subject: Re: ranked subqueries vs distinct question
Next
From: Decibel!
Date:
Subject: Re: ranked subqueries vs distinct question