I want to compare twos rows from a query result, for instance, if 1st row is equal to 2nd Row.
Given a query of the form
SELECT * FROM table_name
if the query results 100 rows, then how do we compare each rows for equality. just i am curious about the sql server how it will implement. basically implementation of Distinct operator. just want to know the how the SQL server will implement in behind the process. as it will help to understand the concept more in clearer way.
Simplest way the sql server may use – to compare hashes of whole rows:
or choosen columns
and if checksums differ – the rows are differ, but if checksum match – it need to check more carefully over exact values of columns, but it will be more or less easier to filter out the results which checksums is not match.
To check the candidates to duplicates: