Use of a $this type function in SQL

63 views Asked by At

I'm trying to create a SQL snippet at the application level to assist in detecting duplicate records based on looking for equalities in a database column. The goal is to identify within each row of a query result through a derived column, the report keys for reports whose columns match the values of that particular row. For example,

SELECT ReportKey
FROM Table
WHERE ColumnValue = $this.ColumnValue;

Trying to reveal for each row the report keys that meet the criteria by which the field specified at ColumnValue is equal to the one for that row. I know that I can't use $ like this in SQL but looking for the proper way to use a $this type function.

1

There are 1 answers

0
Joel On BEST ANSWER

For the task to be accomplished,

SELECT ReportKey from table_a a JOIN table_b b ON a.GUID = b.GUID WHERE a.Column_1 = b.Column_1 and a.Column_2 = b.Column_2 and a.ReportKey != b.ReportKey

This will provide Report Keys for reports with matching values for Column_1 and Column_2 but with separate ReportKey values. Those should be the duplicates, assuming the duplicate logic is sound.