how to do this select?

From: Yi Zhao <yi(dot)zhao(at)alibaba-inc(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: how to do this select?
Date: 2009-02-19 06:27:12
Message-ID: 1235024832.3155.12.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

hi, all, I have a table in postgresql which have 2 columns like this:
a|b
------
X A
X A
Y A
D B
H B
E B
D B
P C
when I do select and order by, I got this:
a | b
---+---
X | A
X | A
Y | A
D | B
H | B
| B
D | B
P | C

I want to get the only 2 rows(limit or random) if the column "b" have
the same value. so, the result of the above is
a | b
---+---
X | A
X | A
D | B
H | B
P | C

how to do that, thanks all!

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joshua D. Drake 2009-02-19 06:35:15 Re: Removing a corrupt database by hand
Previous Message Sameer Mahajan 2009-02-19 06:04:42 postgres wish list