On Fri, 2006-02-10 at 00:11 -0600, Bruno Wolff III wrote: <blockquote type="CITE"><pre>
<font color="#000000">On Tue, Feb 07, 2006 at 01:45:50 -0800,</font>
<font color="#000000"> "superboy143 (sent by Nabble.com)" <<a
href="mailto:lists@nabble.com">lists@nabble.com</a>>wrote:</font>
<font color="#000000">> </font>
<font color="#000000">> 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. I have to write a query such that I have to get only distinct values
suchthat they contain only the substring I need. If I give 10 as substring, then it should return only 100101 or 100102
butnot both i.e if the last two characters are not same it should not return both of them. It should return only values
startingwith 10 the middle two values should be distinct and the last two characters may be anything.</font>
<font color="#000000">You can probably use the Postgres extension DISTINCT ON to do what you want.</font>
<font color="#000000">---------------------------(end of broadcast)---------------------------</font>
<font color="#000000">TIP 3: Have you checked our extensive FAQ?</font>
<font color="#000000"> <a
href="http://www.postgresql.org/docs/faq">http://www.postgresq</a></font>l.org/docs/faq
</pre></blockquote><br /> Try substring(column,1,4). That should return values of 1001, 1002, 1003 when grouped.