Question : Select distinct with binary

Hi I have two tables, one table holds the propertyID's (unique) and the second holds the propimageid's.

I have the code below which works without the Distinct statement, but returns the propid each time for each pic row, but when I use the distinct statement I get the error "The image data type cannot be selected as DISTINCT because it is not comparable."

I want to return a row with the property details and just the top 1 from the  picture table.

Any help would be great.

Thanks.

Code Snippet:
1:
2:
3:
4:
5:
6:
7:
SELECT DISTINCT tp.propID, tp.AddedDate, tp.PropType, tp.NoBedrooms, tp.ShortDesc, tp.City, tp.ReleaseDate, 
		  (select Top 1  ti.BinaryImage FROM dbo.tbl_PropertyImages ti where ti.PropID = tp.PropID ) AS PropertyImage, 
		  ti.ImageID
		FROM dbo.tbl_Properties tp
		INNER JOIN dbo.tbl_propertyImages ti On tp.propID = ti.PropID
		WHERE tp.AddedBy = @UserID
		ORDER BY tp.PropID ASC

Answer : Select distinct with binary

This should work..
1:
2:
3:
4:
5:
6:
7:
8:
SELECT * FROM (
SELECT tp.propID, tp.AddedDate, tp.PropType, tp.NoBedrooms, tp.ShortDesc, tp.City, tp.ReleaseDate,
ti.BinaryImage  AS PropertyImage, ti.ImageID,
row_number() over ( partition by ti.PropID order by ti.PropID) rnum
                FROM dbo.tbl_Properties tp
                INNER JOIN dbo.tbl_propertyImages ti On tp.propID = ti.PropID
                WHERE tp.AddedBy = @UserID) temp
WHERE rnum = 1
Random Solutions  
 
programming4us programming4us