Results 1 to 3 of 3

Thread: [RESOLVED] Select Distinct by an Image Field

  1. #1

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    830

    Resolved [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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    830

    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
  •  



Click Here to Expand Forum to Full Width