|
-
May 31st, 2011, 07:11 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Select Distinct by an Image Field
i have an interesting question for you guys.
Code:
SELECT S.SCHOOLID AS [SCHOOLID],S.SCHOOLNAME AS [SCHOOLNAME],SP.PHOTO AS [PHOTO]
FROM SCHOOLPHOTO SP
INNER JOIN SCHOOL S
ON SP.SCHOOLID = SP.SCHOOLID
WHERE S.SCHOOLID IN (SELECT SCHOOLID FROM #SCHOOLS)
the Photo Field is an Image Datatype Field, i now you can use them in a Distinct or group by , How can i go by have that field there without casting it , because if i cast it it will not work together in Silverlight or any other image control.
Thanks
-
May 31st, 2011, 07:28 PM
#2
Re: Select Distinct by an Image Field
That doesn't seem to make sense. You're retrieving the SchoolID so how could there be duplicates in the first place?
Regardless, if you want to compare binary data like that, I'd suggest generating a hash, e.g. MD5, and storing that in an additional column. You can then compare hashes rather than the actual binary data.
-
Jun 1st, 2011, 04:56 AM
#3
Thread Starter
Fanatic Member
Re: Select Distinct by an Image Field
Thanks i found the Solution, this could do the Trick
Code:
;with cteSchools as (SELECT DISTINCT S.SCHOOLID AS [SCHOOLID],S.SCHOOLNAME AS [SCHOOLNAME]
FROM SCHOOL S
WHERE S.SCHOOLID IN (SELECT SCHOOLID FROM #SCHOOLS))
SELECT S.SCHOOLID AS [SCHOOLID],S.SCHOOLNAME AS [SCHOOLNAME],SP.PHOTO AS [PHOTO]
FROM cteSCHOOLS S
CROSS APPLY (Select TOP (1) PHOTO from SchoolPhoto SP
WHERE SP.SCHOOLID = S.SCHOOLID
ORDER BY SCHOOLID DESC) SP
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|