From naveen_shanbhag@hotmail.com Mon Sep 22 05:22:54 2003 X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 6A053D1B563 for ; Mon, 22 Sep 2003 05:22:54 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 50395-07 for ; Mon, 22 Sep 2003 02:22:24 -0300 (ADT) Received: from hotmail.com (law12-oe66.law12.hotmail.com [64.4.18.201]) by svr1.postgresql.org (Postfix) with ESMTP id F2947D1B4FE for ; Mon, 22 Sep 2003 02:22:22 -0300 (ADT) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Sun, 21 Sep 2003 22:22:23 -0700 Received: from 203.199.110.6 by law12-oe66.adinternal.hotmail.com with DAV; Mon, 22 Sep 2003 05:22:22 +0000 X-Originating-IP: [203.199.110.6] X-Originating-Email: [naveen_shanbhag@hotmail.com] From: "NAGAPPA" To: References: <20030920170512.76693.qmail@web60107.mail.yahoo.com> Subject: selecting duplicate records Date: Mon, 22 Sep 2003 11:07:10 +0530 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_000E_01C380F9.AAFD87E0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Message-ID: X-OriginalArrivalTime: 22 Sep 2003 05:22:23.0066 (UTC) FILETIME=[8096E3A0:01C380C9] X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.4 tagged_above=0.0 required=5.0 tests=HTML_50_60, HTML_FONT_FACE_ODD, REFERENCES X-Spam-Level: X-Archive-Number: 200309/242 X-Sequence-Number: 15220 This is a multi-part message in MIME format. ------=_NextPart_000_000E_01C380F9.AAFD87E0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi I would like to know the following 1. How to select duplicate records only from a single table using a select = query. Thanks in advance Regards naveen ----- Original Message -----=20 From: yogesh selukar=20 To: pgsql-sql@postgresql.org ; sandis@mediaparks.lv=20 Sent: Saturday, September 20, 2003 10:35 PM Subject: Re: [SQL] Simple concatenation in select query Hello Everybpdy, The concatination in select query u can write the query like this. select c.status||' this '||' is '||' the '||' status ' from course_maste= r as c; This works fine Regards Yogesh ---------------------------------------------------------------------------= --- Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software ------=_NextPart_000_000E_01C380F9.AAFD87E0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi
I would like to know the=20 following
1. How to select duplicate r= ecords=20 only from a single table using a select query.
 
Thanks in advance
Regards
naveen
 
----- Original Message -----
Fro= m:=20 yogesh selukar
To: pgsql-sql@postgresql.org ; <= A=20 title=3Dsandis@mediaparks.lv=20 href=3D"mailto:sandis@mediaparks.lv">sandis@mediaparks.lv
Sent: Saturday, September 20, 2003= 10:35=20 PM
Subject: Re: [SQL] Simple concaten= ation=20 in select query

Hello Everybpdy,
     The concatination in select query u can wri= te=20 the query like this.
 
 select c.status||' this '||' is '||' the '||' status '= from=20 course_master as c;
         This works fine
 
Regards
 
Yogesh


Do you Yahoo!?
Yahoo!=20 SiteBuilder - Free, easy-to-use web site design=20 software ------=_NextPart_000_000E_01C380F9.AAFD87E0-- From ch@rodos.fzk.de Mon Sep 22 13:25:59 2003 X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 44C61D1B8C2 for ; Mon, 22 Sep 2003 13:25:59 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 29298-02 for ; Mon, 22 Sep 2003 10:25:17 -0300 (ADT) Received: from fzkmail2.fzk.de (fzkmail2.fzk.de [141.52.27.52]) by svr1.postgresql.org (Postfix) with SMTP id DD425D1B55D for ; Mon, 22 Sep 2003 10:25:12 -0300 (ADT) Received: FROM resy5.fzk.de BY fzkmail2.fzk.de ; Mon Sep 22 15:25:15 2003 +0200 Received: œby rodos.fzk.de with ESMTP (8.8.6 (PHNE_17135)/8.7.1) id PAA11599; Mon, 22 Sep 2003 15:25:14 +0200 (METDST) Message-ID: <3F6EF83A.129807D6@rodos.fzk.de> Date: Mon, 22 Sep 2003 15:25:14 +0200 From: Christoph Haller X-Mailer: Mozilla 4.77 [en] (X11; U; HP-UX B.10.20 9000/780) X-Accept-Language: en MIME-Version: 1.0 To: pgsql-sql@postgresql.org, naveen_shanbhag@hotmail.com Subject: Re: selecting duplicate records Content-Type: text/plain; charset=iso-8859-2 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Amavis-Alert: BAD HEADER Non-encoded 8-bit data (char 9C hex) in message header 'Received' Received: \234by rodos.fzk.de... ^ X-Archive-Number: 200309/251 X-Sequence-Number: 15229 > 1. How to select duplicate records only from a single table using a select > query. > e.g. select sid,count(sid) from location group by sid having count(sid)>1; Do you get the idea? Your request is pretty unspecific, so if this is not what you're asking for, try again. Regards, Christoph From cbbrowne@acm.org Tue Sep 23 03:31:21 2003 X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 53AA8D1B4F0 for ; Tue, 23 Sep 2003 03:31:21 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 43708-04 for ; Tue, 23 Sep 2003 00:31:10 -0300 (ADT) Received: from news.hub.org (unknown [64.117.224.194]) by svr1.postgresql.org (Postfix) with ESMTP id BD89CD1B4FF for ; Tue, 23 Sep 2003 00:31:10 -0300 (ADT) Received: from news.hub.org (host-64-117-224-194.altec1.com [64.117.224.194] (may be forged)) by news.hub.org (8.12.9/8.12.9) with ESMTP id h8N3VAhK031159 for ; Tue, 23 Sep 2003 03:31:10 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id h8N3KLpt029891 for pgsql-sql@postgresql.org; Tue, 23 Sep 2003 03:20:21 GMT From: Christopher Browne X-Newsgroups: comp.databases.postgresql.sql Subject: Re: selecting duplicate records Date: Mon, 22 Sep 2003 23:13:23 -0400 Organization: cbbrowne Computing Inc Lines: 43 Message-ID: References: <3F6EF83A.129807D6@rodos.fzk.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@news.hub.org X-message-flag: Outlook is rather hackable, isn't it? X-Home-Page: http://www.cbbrowne.com/info/ X-Affero: http://svcs.affero.net/rm.php?r=cbbrowne User-Agent: Gnus/5.1003 (Gnus v5.10.3) XEmacs/21.4 (Rational FORTRAN, linux) Cancel-Lock: sha1:r5vHxtjQnkZLd3z0YwzxV+QwrRw= To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/266 X-Sequence-Number: 15244 The world rejoiced as ch@rodos.fzk.de (Christoph Haller) wrote: >> 1. How to select duplicate records only from a single table using a > select >> query. >> > e.g. > select sid,count(sid) from location group by sid having count(sid)>1; > > Do you get the idea? > Your request is pretty unspecific, so if this is not what you're asking > for, > try again. The aggregate is likely to perform horrifically badly. Here might be an option: Step 1. Find all of the duplicates... select a.* into temp table sid from some_table a, some_table b where a.oid < b.oid and a.field1 = b.field1 and a.field2 = b.field2 and a.field3 = b.field3 and ... a.fieldn = b.fieldn; Step 2. Look for the matching entries in the source table... select a.* from some_table a, sid b where a.field1 = b.field1 and a.field2 = b.field2 and a.field3 = b.field3 and ... a.fieldn = b.fieldn; [There's a weakness here; if there are multiple dupes, they may get picked multiple times in the second query :-(.] -- If this was helpful, rate me http://cbbrowne.com/info/rdbms.html As Will Rogers would have said, "There is no such thing as a free variable." -- Alan Perlis From guy@incentre.net Tue Sep 23 20:34:43 2003 X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id B31CAD1B58D for ; Tue, 23 Sep 2003 20:34:43 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 46274-04 for ; Tue, 23 Sep 2003 17:34:34 -0300 (ADT) Received: from bach.ccinet.ab.ca (bach.ccinet.ab.ca [198.161.96.1]) by svr1.postgresql.org (Postfix) with ESMTP id E94BDD1B519 for ; Tue, 23 Sep 2003 17:34:31 -0300 (ADT) Received: from incentre.net (guy-pc.incentre.net [206.75.213.195] (may be forged)) by bach.ccinet.ab.ca (8.12.8p2/8.12.8) with ESMTP id h8NKXYaj023705 for ; Tue, 23 Sep 2003 14:33:34 -0600 (MDT) (envelope-from guy@incentre.net) Message-ID: <3F70AE58.7030308@incentre.net> Date: Tue, 23 Sep 2003 14:34:32 -0600 From: Guy Fraser Organization: The Internet Centre User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20030225 X-Accept-Language: en-ca, en-gb, en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: selecting duplicate records References: <3F6EF83A.129807D6@rodos.fzk.de> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/276 X-Sequence-Number: 15254 This is a test I did on one of my tables where I put duplicated entries : select * from acct_other_2003sep except select sep.* from ( select min(oid) as min_oid, "Acct-Status-Type", "User-Name", "Realm", "Acct-Session-Time", "Acct-Input-Octets", "Acct-Output-Octets", "Called-Station-Id", "Calling-Station-Id", "Acct-Terminate-Cause", "Framed-IP-Address", "Service-Type", "Framed-Protocol", "Client-IP-Address", "NAS-IP-Address", "NAS-Port-Type", "NAS-Port-Id", "Acct-Session-Id", "Acct-Link-Count", "Acct-Multi-Session-Id" from acct_other_2003sep group by "Acct-Status-Type", "User-Name", "Realm", "Acct-Session-Time", "Acct-Input-Octets", "Acct-Output-Octets", "Called-Station-Id", "Calling-Station-Id", "Acct-Terminate-Cause", "Framed-IP-Address", "Service-Type", "Framed-Protocol", "Client-IP-Address", "NAS-IP-Address", "NAS-Port-Type", "NAS-Port-Id", "Acct-Session-Id", "Acct-Link-Count", "Acct-Multi-Session-Id" ) as min_sep, acct_other_2003sep as sep where sep.oid = min_sep.min_oid ; From the above example you can see how to use a subselect to get a unique list then using except, you can get the records that were not unique. This may not be exactly what you want but it does implement some of the methods required to get around using using temporary tables. For some tasks using temporary tables may be more suitable if your query becomes too complex and or you run out of memory/time. Hope this helps. Guy Christopher Browne wrote: >The world rejoiced as ch@rodos.fzk.de (Christoph Haller) wrote: > > >>>1. How to select duplicate records only from a single table using a >>> >>> >>select >> >> >>>query. >>> >>> >>> >>e.g. >>select sid,count(sid) from location group by sid having count(sid)>1; >> >>Do you get the idea? >>Your request is pretty unspecific, so if this is not what you're asking >>for, >>try again. >> >> > >The aggregate is likely to perform horrifically badly. Here might >be an option: > >Step 1. Find all of the duplicates... > >select a.* into temp table sid from some_table a, some_table b > where a.oid < b.oid and > a.field1 = b.field1 and > a.field2 = b.field2 and > a.field3 = b.field3 and > ... > a.fieldn = b.fieldn; > >Step 2. Look for the matching entries in the source table... > >select a.* from some_table a, sid b > where > a.field1 = b.field1 and > a.field2 = b.field2 and > a.field3 = b.field3 and > ... > a.fieldn = b.fieldn; > >[There's a weakness here; if there are multiple dupes, they may get >picked multiple times in the second query :-(.] > > -- Guy Fraser Network Administrator The Internet Centre 780-450-6787 , 1-888-450-6787 There is a fine line between genius and lunacy, fear not, walk the line with pride. Not all things will end up as you wanted, but you will certainly discover things the meek and timid will miss out on.