Question : Check for Duplicate records during update

Hi

I have peculiar situation and problem when user updates a record.

Let me go in detail. Let us say I have table called title. where I have title_ID and description. User saves a record as value 'Mr' and next time updates the same record as 'Mr' again. I am checking from DB whether 'Mr' exists in DB and that user is updating the same record with following query

SELECT TITLE.CREATEDDATE
AS "Createddate", TITLE.CREATEDUSER_ID
AS "CreateduserId", TITLE.DESCRIPTION
AS "Description", TITLE.FLAG
AS "Flag", TITLE.MODIFIEDDATE
AS "Modifieddate", TITLE.MODIFIEDUSER_ID
AS "ModifieduserId", TITLE.TITLE_ID
AS "TitleId" FROM TITLE
WHERE UPPER(TITLE.DESCRIPTION) = UPPER('Mr')
AND TITLE.FLAG = 0 AND TITLE.TITLE_ID <> 1

This is 100% right and no issues

Now the problem scenario

I have one more table called AffiliateMember with columns AFFILIATEMEMBER AND AFFILIATECLUBNO where both of these together form primary key

In this scenario the above query will not work. Is there any solution for this other than adding one more primary key which is unique

Answer : Check for Duplicate records during update

Hi GRC,


You mean that you want to check if the duplicated data when update the table AffiliateMember?

The table has primary key (AFFILIATEMEMBER ,AFFILIATECLUBNO), so you can check it by  a query with 2 above fields, such as:

(select 1 from AffiliateMember where upper(AFFILIATEMEMBER) ='VIP'  and AFFILIATECLUBNO = '1')

Random Solutions  
 
programming4us programming4us