Re: how to do this select?

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: Yi Zhao <yi(dot)zhao(at)alibaba-inc(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: how to do this select?
Date: 2009-02-19 06:49:17
Message-ID: 499D00ED.5090207@postnewspapers.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Yi Zhao wrote:

> 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!
>
>

I don't understand what you want based on your description and your
example results. What do you mean by "if the column `b' have the same
value" ?

By the way, when you're posting this kind of question it's really
helpful to send SQL code to set up your test environment. For example,
if you had sent:

CREATE TABLE ab (a text, b text);

INSERT INTO ab (a,b) VALUES
('X','A'),('X','B'),('Y','A'),('D','B'),('H','B'),('E','B'),('D','B'),('P','C');

... then it would've saved the hassle of assembling a test table.

--
Craig Ringer

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Yi Zhao 2009-02-19 07:09:44 Re: how to do this select?
Previous Message Mike Christensen 2009-02-19 06:47:21 Re: Removing a corrupt database by hand