pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: chris smith <dmagick@gmail.com>
To: Dani CastaƱos <dcastanos@androme.es>
Cc: pgsql-php@postgresql.org
Subject: Re: Alphabetic Pager Class
Date: Thu, 21 Jun 2007 21:01:06 +1000
Message-ID: <3c1395330706210401l14c4656fv2af5787a34d5c80f@mail.gmail.com> (raw)
In-Reply-To: <467A39A8.6060008@androme.es>
References: <467A39A8.6060008@androme.es>

On 6/21/07, Dani CastaƱos <dcastanos@androme.es> wrote:
> Hello!
>
> I'm trying to build an alphabetic pager class. For instance, an address
> book ordered by the Last Name where only results begining with A are
> shown, and A - B - C - D - ... links below to change the letter which
> i'm filtering for.
> The point is I don't want to have enabled those links wich have no
> occurrences in them. So, I'm wondering which is the best way to do the
> query.
>
> My first thought to know how many results are there for each, is to do
> something like:
> SELECT COUNT(field) FROM table WHERE UPPER( field )  LIKE UPPER( 'A%' );
> SELECT COUNT(field) FROM table WHERE UPPER( field )  LIKE UPPER( 'B%' );
> SELECT COUNT(field) FROM table WHERE UPPER( field )  LIKE UPPER( 'C%' );

select count(*), upper(substr(field, 1, 1)) from table group by
upper(substr(field, 1, 1));

-- 
Postgresql & php tutorials
http://www.designmagick.com/



view thread (4+ messages)  latest in thread

Message-ID: <3c1395330706210401l14c4656fv2af5787a34d5c80f@mail.gmail.com>
Permalink:  ../3c1395330706210401l14c4656fv2af5787a34d5c80f@mail.gmail.com/
Also on:    postgresql.org/message-id/3c1395330706210401l14c4656fv2af5787a34d5c80f@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: dmagick@gmail.com, dcastanos@androme.es
  Subject: Re: Alphabetic Pager Class
  In-Reply-To: <3c1395330706210401l14c4656fv2af5787a34d5c80f@mail.gmail.com>
  References: <467A39A8.6060008@androme.es> <3c1395330706210401l14c4656fv2af5787a34d5c80f@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox