0

I have a subquery which can return multiple results if a customer has duplicated sales codes.

I currently LIMIT 1 to just return the most recent but ... Is there away to return NULL or "DUPLICATE" if RESULT > 1?

I am using this field to overwrite a field which already has a default - therefore, I would just prefer to use the default or raise an alert for rectification.

  • if a customer has duplicated sales codes. This is practically equal to "My data is inconsistent, but I don't want to purify my data and do something to prevent this in future". It's bad... It is necessary to treat the disease and not its symptoms. I'd recommend you: 1) remove duplicates; 2) create unique index which prevents duplicates. – Akina Mar 22 at 5:02
  • Did you read the OP - "I would just prefer to use the default or raise an alert for rectification." – php-b-grader Mar 24 at 21:59
0

You could try something like this, add a select case to your subquery

select (select case when (select count(*) from subquery) >1 then 'duplicate' else 'not duplicate' end)

Though I'm not sure if I would recommend that, but there is one method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.