Display duplicate record (merged) [message #288955] |
Wed, 19 December 2007 02:33 |
ntc2000
Messages: 25 Registered: September 2005
|
Junior Member |
|
|
Hi,
I have a case where i need to query out multiple duplicated records from a table. (Transno and refno(reference no) is the primary key for table_a).
SQL> select refno,hdbatchid, count(transno) as counter from table_a group by refno,hdbatchid order by refno;
REFNO HDBATCHID COUNTER
-------------- ---------- ----------
EFT04100700276 NR267 51 (means 51 records)
EFT19090700250 2007T0333 379 (means 379 records)
EFT19090700251 2007T0333 345 (means 345 records)
EFT19090700254 2007T0332 616 (means 616 records)
EFT25090700260 T0002 3 (means 3 records)
EFT25090700281 T0002 1 (means 1 records)
6 rows selected.
How can i create a query where the output will be shown as below?? It's only shown out the duplicate hdbatchid records.
REFNO HDBATCHID COUNTER
-------------- ---------- ----------
EFT19090700250 2007T0333 379 (means 379 records)
EFT19090700251 2007T0333 345 (means 345 records)
EFT25090700260 T0002 3 (means 3 records)
EFT25090700281 T0002 1 (means 1 records)
6 rows selected.
thank for help.
|
|
|
|
|
|
|
|
how to get only duplicate records from a table by using groupby [message #289001 is a reply to message #288955] |
Wed, 19 December 2007 04:41 |
msg2ajay
Messages: 51 Registered: June 2007 Location: KUALA LUMPUR
|
Member |
|
|
hello,
my sample query is like this:
select refno,hdbatchid, count(eftno) as counter from eftag group by refno,hdbatchid order by refno;
REFNO HDBATCHID COUNTER
------ -------- ----------
DE343 NR267 51 (means 51 records)
DE250 2007T0333 1 (means 1 records)
DE271 2007T0333 345 (means 345 records)
DE284 2007T0332 616 (means 616 records)
DE288 T0002 3 (means 3 records)
DE299 T34334 1 (means 1 record)
what i want is like below
DE243 NR267 51 (means 51 records)
DE271 2007T0333 345 (means 345 records)
DE284 2007T0332 616 (means 616 records)
DE288 T0002 3 (means 3 records)
Here i need to exclude the counter(1 record) because i have only one record(no duplicate record).
thanQ in advance,
Ajay.
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: how to get only duplicate records from a table by using groupby [message #289348 is a reply to message #289016] |
Thu, 20 December 2007 20:48 |
ntc2000
Messages: 25 Registered: September 2005
|
Junior Member |
|
|
thank for all moderator reply. AJAY is my colleague who I asked him the same question. He post on here as well.
SQL> select refno,hdbatchid, count(transno) as counter from table_a group by refno,hdbatchid order by refno;
REFNO HDBATCHID COUNTER
-------------- ---------- ----------
EFT04100700276 NR267 51 (means 51 records)
EFT19090700250 2007T0333 379 (means 379 records)
EFT19090700251 2007T0333 345 (means 345 records)
EFT19090700254 2007T0332 616 (means 616 records)
EFT25090700260 T0002 3 (means 3 records)
EFT25090700281 T0002 1 (means 1 records)
6 rows selected.
I want to query out the output as below.
REFNO HDBATCHID COUNTER
-------------- ---------- ----------
EFT19090700250 2007T0333 379 (means 379 records)
EFT19090700251 2007T0333 345 (means 345 records)
EFT25090700260 T0002 3 (means 3 records)
EFT25090700281 T0002 1 (means 1 records)
I want to query the duplicate HDBATCHID which have difference refno. Based on above query, I have group up the transno and it's has 379 records for hdbatchid=EFT19090700250 and 345 records hdbatchid=EFT19090700251.
And by using the above group by query, how can i make it so that it's will group the refno again based on previous group by result and display the result i want.
Thank for reply.
|
|
|
Re: how to get only duplicate records from a table by using groupby [message #289349 is a reply to message #289348] |
Thu, 20 December 2007 20:52 |
ntc2000
Messages: 25 Registered: September 2005
|
Junior Member |
|
|
Quote: | And by using the above group by query, how can i make it so that it's will group the refno again based on previous group by result and display the result i want.
|
sorry for mistake, suppose is..
And by using the above group by query, how can i make it so that it's will group the hdbatchid again based on previous group by result and count the number of refno(which refno=2) and display the result i want.
|
|
|
Re: how to get only duplicate records from a table by using groupby [message #289350 is a reply to message #289349] |
Thu, 20 December 2007 21:30 |
ntc2000
Messages: 25 Registered: September 2005
|
Junior Member |
|
|
one of my colleague found the query.
SQL> select refno,hdbatchid, sum(transno) as counter,count(refno) from (select refno,hdbatchid,count(transno)as transnocnt from table_a group by refno,hdbatchid) test where hdbatchid in (select hdbatchid from (select refno,hdbatchid,count(transno) as transnocnt from table_a group by refno,hdbatchid)test2 group by hdbatchid having count(hdbatchid)>1)group by refno,hdbatchid order by refno;
REFNO HDBATCHID COUNTER COUNT(REFNO)
-------------- ---------- ---------- ------------
EFT19090700250 2007T0333 379 1
EFT19090700251 2007T0333 345 1
EFT25090700260 T0002 3 1
EFT25090700281 T0002 1 1
|
|
|
Re: how to get only duplicate records from a table by using groupby [message #289352 is a reply to message #289350] |
Thu, 20 December 2007 21:33 |
ntc2000
Messages: 25 Registered: September 2005
|
Junior Member |
|
|
select refno,hdbatchid, sum(transno) as counter,count(refno) from
(select refno,hdbatchid,count(transno)as transnocnt from table_a
group by refno,hdbatchid) test where hdbatchid in (select hdbatchid
from (select refno,hdbatchid,count(transno) as transnocnt from
table_a group by refno,hdbatchid)test2 group by hdbatchid having
count(hdbatchid)>1)group by refno,hdbatchid order by refno
|
|
|
|
|