Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 945DA9FB684 for ; Thu, 21 Jun 2007 06:12:20 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 42339-03 for ; Thu, 21 Jun 2007 06:12:17 -0300 (ADT) X-Greylist: delayed 00:30:54.837329 by SQLgrey-1.7.5 Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 89D149FBDA2 for ; Thu, 21 Jun 2007 06:12:17 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from fafnir.androme.com (fafnir.androme.com [62.58.96.158]) by svr4.postgresql.org (Postfix) with ESMTP id E233D5AF8CF for ; Thu, 21 Jun 2007 08:41:21 +0000 (GMT) Received: by fafnir.androme.com (Postfix, from userid 1003) id 1B381B9165D; Thu, 21 Jun 2007 10:41:13 +0200 (CEST) Message-ID: <467A39A8.6060008@androme.es> Date: Thu, 21 Jun 2007 10:41:12 +0200 From: =?ISO-8859-1?Q?Dani_Casta=F1os?= User-Agent: Thunderbird 2.0.0.4 (Windows/20070604) MIME-Version: 1.0 To: pgsql-php@postgresql.org Subject: Alphabetic Pager Class Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200706/10 X-Sequence-Number: 3812 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%' ); ... and so on. But obviously, it is not an effcient way to do this. Is it possible to reduce this to only one query?? Thank you in advance. Dani