Re: How to find records with the same field?

From: Devrim GUNDUZ <devrim(at)gunduz(dot)org>
To: Joost Kraaijeveld <J(dot)Kraaijeveld(at)Askesis(dot)nl>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to find records with the same field?
Date: 2004-07-20 09:46:45
Message-ID: Pine.LNX.4.44.0407201244560.23229-100000@emo.org.tr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

On Tue, 20 Jul 2004, Joost Kraaijeveld wrote:

> I have a table with column1, column2, column3 and column4. How do I get
> all records, sorted by column4 that have the same column1,column2 and
> column3?

SELECT * from table_name WHERE (c1=c2) AND (c2=c3) ORDER BY c4;

will work, I think:
===================
test=> CREATE TABLE joost (c1 varchar(10), c2 varchar(10), c3 varchar(10),
c4 varchar(10));
CREATE TABLE
test=> INSERT INTO joost VALUES ('test1','test1','test1','remark');
INSERT 1179458 1
test=> INSERT INTO joost VALUES ('test1','test1','test1','remark2');
INSERT 1179459 1
test=> INSERT INTO joost VALUES ('test1','test2','test3','nevermind');
INSERT 1179460 1
test=> SELECT * from joost ;
c1 | c2 | c3 | c4
- -------+-------+-------+-----------
test1 | test1 | test1 | remark
test1 | test1 | test1 | remark2
test1 | test2 | test3 | nevermind
(3 rows)

test=> SELECT * from joost WHERE (c1=c2) AND (c2=c3) ORDER BY c4
test-> ;
c1 | c2 | c3 | c4
- -------+-------+-------+--------
test1 | test1 | test1 | remark
test1 | test1 | test1 | remark
(2 rows)
===================

Regards,

- --
Devrim GUNDUZ
devrim~gunduz.org devrim.gunduz~linux.org.tr
http://www.tdmsoft.com
http://www.gunduz.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFA/OoHtl86P3SPfQ4RAqdmAKDVyBy6LFR1zFk4phuZnkHdaOk4SACaAwz9
JUhJUBtGoabox8VG9EpTkBQ=
=SfQ5
-----END PGP SIGNATURE-----

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Peter Alberer 2004-07-20 10:03:15 Re: How to find records with the same field?
Previous Message Joost Kraaijeveld 2004-07-20 09:38:33 How to find records with the same field?