Re: Alphabetic Pager Class

"chris smith" <[email protected]>
Newsgroups gmane.comp.db.postgresql.php
Message-ID <[email protected]>
On 6/21/07, Dani Castaños <[email protected]> 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/

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.