Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query dups in 1 table & update 2 other tables then delete dups

Status
Not open for further replies.

WILKIEB

Programmer
Apr 27, 2005
5
US
I’m new to SQL, and as an old RPG’r I know how I would do it that way but need help here. I can identify the duplicates

SELECT FIELDA, FIELDB, FLDR
FROM TableA c
WHERE c.FLDR <> (
SELECT MAX (FLDR ) FROM TableA
WHERE FIELDA = c.FIELDA
AND FIELDB = c.FIELDB)
order by FIELDA, FIELDB, FLDR

I need to identify the duplicates in TableA of FIELDA FIELDB, then use the lowest FLDR of those duplicates in TableA to update the FLDR in TableB and TableC , then delete duplicates in TableA with FLDR higher than the one used for the update

TableA
FLDR FIELDA FIELDB
400897 TR 42444
448117 TR 42444
440182 TR 42444
401010 GA 12345
401898 GA 12345
404054 GA 777888

TableB
FLDR PARR
400897 75676
448117 75676
401010 60111
404054 603040

TableC
FLDR PARR DOCR
400897 75676 12
448117 75676 15
440182 23
401010 60111 100
401898 49
404054 603040 54

.
Data Should look like this when finished.
TableA
FLDR FIELDA FIELDB
400897 TR 42444
401010 GA 12345
404054 GA 777888

TableB
FLDR PARR
400897 75676
400897 75676
401010 60111
404054 603040

TableC
FLDR PARR DOCR
400897 75676 12
400897 75676 15
400897 23
401010 60111 100
401010 49
404054 603040 54


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top