Re: How to remove duplicate lines but save one of the lines?

From: Kedar <kedarr(at)netcore(dot)co(dot)in>
To: A B <gentosaker(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to remove duplicate lines but save one of the lines?
Date: 2008-08-04 15:10:50
Message-ID: 48971BFA.6010703@netcore.co.in
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Julio Cesar Sánchez González wrote:
> A B wrote:
>> I have a table with rows like this
>> A 1
>> A 1
>> B 3
>> B 3
>> C 44
>> C 44
>> and so on.
>>
>> and I want it to be
>> A 1
>> B 3
>> C 44
>>
>> so how can I remove the all the duplicate lines but one?
>>
>>
You think this would help?
create table temp(text varchar(20),id integer );
INSERT INTO temp values('A',10);
INSERT INTO temp values('A',10);
INSERT INTO temp values('B',20);
INSERT INTO temp values('B',20);
INSERT INTO temp values('B',20);

select * from temp;
text | id
------+----
A | 10
A | 10
B | 20
B | 20
B | 20

select text,id, count(1) from temp group by 1,2;

text | id | count
------+----+-------
A | 10 | 2
B | 20 | 3

and forget about the count from the result set.

--

Thanks & Regards

Kedar Parikh
Netcore Solutions Pvt. Ltd.

Tel: +91 (22) 6662 8135
Mob: +91 9819634734
Email: kedar(at)netcore(dot)co(dot)in
Web: www.netcore.co.in

===================================================================
sms START NEWS <your city> to 09845398453 for Breaking News and Top
Stories on Business, Sports & Politics. For more services visit
http://www.mytodaysms.com
===================================================================

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Teemu Juntunen 2008-08-04 17:19:42 Howto disable login?
Previous Message Glyn Astill 2008-08-04 14:33:40 Re: index speed and failed expectations?