[Date Prev][Date Next][Thread Prev][Thread Next]
[Author Index] [Date Index] [Thread Index]
[SQR-USERS Info] [SQRUG Home Page]

Duplicate Records from 2 tables



I have a question relating to duplicate records.
Here's the scenario:
I have 2 tables, a voucher table (table1) and its corresponding voucher history
table (table2).  I would like to pull off any duplicate records from the two
tables as follows (based on 3 keys, invoice_id, invoice_dt, gross_amt):
1. all duplicates that exist w/in table1 only
2. all duplicates that exist w/in tabe2 only
3. all duplicates that exist in both table1 and table2

The following code pulls duplicate records of the voucher table only. When I
tried to add logic for table2, the code bombed.  How should I go about selecting
for all these records?  Would a union work?  If so, how, b/c I tried adding
UNION but that failed, too.

fyi, i'm using SQLBase Server 6.1.2

Thanks for you help!!
Lisa


begin-SELECT
INVOICE_ID,
INVOICE_DT,
GROSS_AMT
    move &INVOICE_ID to $INVOICE_ID
    move &INVOICE_DT to $INVOICE_DT
    move &GROSS_AMT  to #GROSS_AMT
    move 'N' to $FOUND
    do Get-Voucher-Information
    if $FOUND = 'Y'
        print ' '    (+1,1)
    end-if
FROM PS_VOUCHER
GROUP BY INVOICE_ID, INVOICE_DT, GROSS_AMT
HAVING COUNT(*) > 1
end-select