Here is an example of some of my data. I am trying to remove all extra data where the QueryID and RoyID are the same as other entries in the table, however, I would like to keep atleast one record. I'm not sure I'll be able to use the min or max functions on the ID column as some of the records have IDs like DEMO_12345 etc.
ID QUERY_ID ROYALTY_ID
RTSQR1652 SQ1421 ROY25644005
RTSQR1653 SQ1421 ROY25636406
RTSQR1654 SQ1421 ROY25636557
RTSQR1655 SQ1421 ROY25636558
RTSQR1656 SQ1421 ROY25636559
RTSQR1657 SQ1421 ROY25636560
I was thinking to use ROWID instead of ID. Would the following query work?
DELETE FROM RT_SOURCE_QUERY_ROYALTIES WHERE ROWID NOT IN (
SELECT MAX(ROWID) FROM RT_SOURCE_QUERY_ROYALTIES GROUP BY ROYALTY_ID, QUERY_ID);