Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Duplicates in database view

jay97
Tera Contributor

I have this database view, data is reflecting correctly, but it is coming twice ( meaning duplicate), what should I change in the where clause to avoid duplicates records?

1000206573.png

1 REPLY 1

pavani_paluri
Tera Guru
Tera Guru

Hi @jay97 ,

 

You’ve built a database view that connects metric definition, metric instance, and your custom case table (x_amoss_csm_proc_case).
The problem is that one metric definition can link to many metric instances, and one case can link to many metric results.
Because of that, the same case shows up more than once — not because the data is wrong, but because the join is too broad.
Match on the unique ID (sys_id)
Add a filter to cut out extras
Keep only the fields you care about
The more fields you pull in, the more chances you’ll see duplicates.
Focus on the case number + metric you actually need.
Handle deduplication in reports if needed
ServiceNow’s database views don’t support fancy SQL like DISTINCT or GROUP BY.
If you still see duplicates, you can make your report show only unique rows.

 

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Pavani P