X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8F3239DCAD6 for ; Tue, 7 Feb 2006 06:38:31 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 08216-10 for ; Tue, 7 Feb 2006 06:38:33 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by postgresql.org (Postfix) with ESMTP id 67C2C9DCA16 for ; Tue, 7 Feb 2006 06:38:29 -0400 (AST) Received: from mainbox.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id 99616426559; Tue, 7 Feb 2006 10:35:00 +0000 (GMT) Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id EBCA915EA4; Tue, 7 Feb 2006 10:34:59 +0000 (GMT) Message-ID: <43E877D3.9090509@archonet.com> Date: Tue, 07 Feb 2006 10:34:59 +0000 From: Richard Huxton User-Agent: Thunderbird 1.5 (X11/20051201) MIME-Version: 1.0 To: superboy143 Cc: pgsql-sql@postgresql.org Subject: Re: query References: <2798161.post@talk.nabble.com> In-Reply-To: <2798161.post@talk.nabble.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.116 required=5 tests=[AWL=0.116] X-Spam-Score: 0.116 X-Spam-Level: X-Archive-Number: 200602/55 X-Sequence-Number: 24065 superboy143 (sent by Nabble.com) wrote: > Hello, > > I have a table in which I have a field with format like 100101. It > has many values like 100101, 100102, 100103, 100201, 100202, 100301. OK - so they look like numbers but aren't. > I have to write a query such that I have to get only distinct values > such that they contain only the substring I need. If I give 10 as > substring, then it should return only 100101 or 100102 but not both > i.e if the last two characters are not same it should not return both > of them. The statement of the rule and the example contradict each other. Surely 100101 and 100102 are distinct values. Surely they contain "10" as a substring. So according to your rule the should be returned. > It should return only values starting with 10 the middle two > values should be distinct and the last two characters may be > anything. This seems to agree with your example and not your rule. So: 1. You don't want distinct values of your field, you want distinct substrings of your field? 2. You don't want to match a substring, you want to match the start of the string? 3. You want only one of 100101 or 100102 but you don't care which? Is this correct? By the way - it looks to me like you are trying to store multiple values in one column. If you split the values into their own columns I'd guess your query would be much easier. -- Richard Huxton Archonet Ltd