Hi,
The main idea is to compare hash bytes with 'md5' algorithm.
I have create table like your columns
create table emp (auto_id int identity(1,1), Catelog_Id int, CatelogImage Image)
Next i have populate with script (running many times) :
Insert emp (Catelog_Id, CatelogImage)
Select 1001, BulkColumn from Openrowset( Bulk 'D:\CodeProject1.jpg', Single_Blob)
Insert emp (Catelog_Id, CatelogImage)
Select 1001, BulkColumn from Openrowset( Bulk 'D:\CodeProject2.jpg', Single_Blob)
Insert emp (Catelog_Id, CatelogImage)
Select 1001, BulkColumn from Openrowset( Bulk 'D:\CodeProject3.jpg', Single_Blob)
finally to list all id's for the same image, run this script :
;
with hashimage (
hashimage_hash
,hashimage_count
)
as (
select hashbytes('md5', cast([catelogimage] as varbinary)),count(*)
from emp
group by hashbytes('md5', cast([catelogimage] as varbinary))
having count(*) > 1
)
select hashimage_hash
,stuff((
select ',' + rtrim(auto_id)
from emp sub
where hashbytes('md5', cast([catelogimage] as varbinary)) = hashimage_hash
for xml path('')
), 1, 1, '')
from hashimage
Source :
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/d55317cc-8bff-4e7d-a34c-f75da7e4778b/how-to-compare-imagevarbinary-column[
^]