Re: How to find records with the same field? - Mailing list pgsql-general

From Devrim GUNDUZ
Subject Re: How to find records with the same field?
Date
Msg-id Pine.LNX.4.44.0407201244560.23229-100000@emo.org.tr
Whole thread Raw
In response to How to find records with the same field?  ("Joost Kraaijeveld" <J.Kraaijeveld@Askesis.nl>)
List 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-----


pgsql-general by date:

Previous
From: "Joost Kraaijeveld"
Date:
Subject: How to find records with the same field?
Next
From: "Peter Alberer"
Date:
Subject: Re: How to find records with the same field?