

How to write an SQL query to identify duplicate values in a specific field?
source link: https://www.codesd.com/item/how-to-write-an-sql-query-to-identify-duplicate-values-in-a-specific-field.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to write an SQL query to identify duplicate values in a specific field?
This is the table I'm working with:

I would like to identify only the ReviewIDs that have duplicate deduction IDs for different parameters.
For example, in the image above, ReviewID 114 has two different parameter IDs, but both records have the same deduction ID.
For my purposes, this record (ReviewID 114) has an error. There should not be two or more unique parameter IDs that have the same deduction ID for a single ReviewID.
I would like write a query to identify these types of records, but my SQL skills aren't there yet. Help?
Thanks!
Update 1: I'm using TSQL (SQL Server 2008) if that helps
Update 2: The output that I'm looking for would be the same as the image above, minus any records that do not match the criteria I've described.
Cheers!
SELECT * FROM table t1 INNER JOIN (
SELECT review_id, deduction_id FROM table
GROUP BY review_id, deduction_id
HAVING COUNT(parameter_id) > 1
) t2 ON t1.review_id = t2.review_id AND t1.deduction_id = t2.deduction_id;
http://www.sqlfiddle.com/#!3/d858f/3
If it is possible to have exact duplicates and that is ok, you can modify the HAVING clause to COUNT(DISTINCT parameter_id).
Recommend
-
7
Find values in an array with duplicate values advertisements I have an array of customer names. This array is full of duplicates, and needs to be...
-
6
Lodash: Convert the array with the duplicate values in object with the number of repeated instances advertisements Here is my array:
-
10
TS2300 error: Duplicate identify 'PropertyKey' in node_modules/@types/core-js/index.d.ts advertisements I have these errors in node_modules/@types/...
-
5
Lists the number of duplicate values advertisements I have the following a Rails ActiveRecord association where...
-
4
Find out what makes you or your team tick by whittling down this template of 210 values
-
9
Count the number of duplicate values on a column for specific values from another column in MySQL? advertisements I've...
-
5
How to remove duplicate values from an array in PHP 1359 views 2 years ago PHP Use the PHP array_unique(...
-
14
SAS administrator tip: How to identify and prevent duplicate librefs in SAS metadata
-
7
Removing Duplicate Rows (Based on Values from Multiple Columns) From SQL Table ...
-
13
How to Eliminate Duplicate Values Based on Only One Column of the Table in SQL? ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK