Re: Most specific match using between

From: mmiranda(at)americatel(dot)com(dot)sv
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Most specific match using between
Date: 2005-04-21 16:18:31
Message-ID: 76E0DAA32C39D711B6EC0002B364A6FA043DCE1E@amsal01exc01.americatel.com.sv
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 2005-04-21 at 10:51, mmiranda(at)americatel(dot)com(dot)sv wrote:
> > These are the details, i have these table
> >
> > name | start | end
> > ---------------+---------------+-----------------
> > general | 2660000 | 2669999
> > specific | 2660124 | 2660124
> > (2 rows)
> >
> >
> > unsing the query: select name where '2660124' between start and end
> >
> > i got:
> >
> >
> > name
> > ---------
> > general
> > specific
> >
> >
> > How can i get only specific?
>
> Do you want the ONE row that's closest, or a set of rows that
> are fairly
> close? Not sure what your specification it exactly, but how about:
>
> select name where '2660124' between start and end order by abs
> (start-end) limit 1;
>

I want the one row that is closest, your query seems to work...

---

Browse pgsql-general by date

  From Date Subject
Next Message Steve Atkins 2005-04-21 16:25:06 Re: Most specific match using between
Previous Message Thomas Hallgren 2005-04-21 16:16:30 Re: CURRENT_TIMESTAMP vs actual time