Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Showing the duplicates
Message
From
16/04/2003 12:21:01
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
16/04/2003 11:52:51
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00778403
Message ID:
00778422
Views:
13
This message has been marked as the solution to the initial question of the thread.
>As an audit exercise, I need to find duplicate check numbers.
>That is if I do find a check number that has been
>used more than once for a specific bank I need to ignore
>the first instance but capture the other (dups).
>
>In the examle below there are 3 instances of check # 1
>written on bank 'B'. What I'd like returned are PKs
>3, 4 and 5 or more preferably only PKs 4 and 5 (3 is
>the first one).
>
>Can this be done in a SQL single statement?
>
>
>
>CREATE CURSOR bnk_trx (pk I, bnk c(1), chkno C(1), amt y)
>INSERT INTO bnk_trx VALUES (1, 'A', '1', 1)
>INSERT INTO bnk_trx VALUES (2, 'A', '2', 2)
>INSERT INTO bnk_trx VALUES (3, 'B', '1', 1)
>INSERT INTO bnk_trx VALUES (4, 'B', '1', 2)
>INSERT INTO bnk_trx VALUES (5, 'B', '1', 3)
>
>SELECT * from bnk_trx WHERE EXISTS
>(SELECT bnk, chkno, count(*) cnt FROM bnk_trx GROUP BY bnk, chkno ;
>having count(*) > 1)
>
>
SELECT distinct a.* ;
  from bnk_trx a inner join bnk_trx b ;
   on a.pk > b.pk and a.bnk = b.bnk and a.chkno = b.chkno 
Update - or (should be faster) :
select * from bnk_trx a ;
  where a.pk > some ;
  (select pk from bnk_trx b where a.bnk = b.bnk and a.chkno = b.chkno )
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform