문제

I am trying to loop over query with a nested query. The code that I have so far:

<cfloop query="hashTableLatest">
    <cfquery name="getDifferentImages" dbtype="query">
        SELECT image, imageHash
        FROM hashTable
        WHERE imageHash = <cfqueryparam cfsqltype="cf_sql_varchar" value="#hashTableLatest.imageHash#" />
    </cfquery>
</cfloop>

The problem that I have is that it doesn't loop dynamically through the cfqueryparam. It just gets the first value from the hashTableLatest. Can anyone tell me what am I doing wrong? How can I loop through a query and dynamically change the cfqueryparam?

EDITED To get all the information I need in a single query:

select a.imageHash
from tblHashLatest a
WHERE a.imageHash in (SELECT c.imageHash
                  FROM tblHash c
              WHERE a.imageHash <> c.imageHash)

I think that the above SQL should get me all the information I need. The result I am looking for is to get all imageHashes that are not same

도움이 되었습니까?

해결책

There are a couple of options. One is to not use a loop and just do this:

WHERE imageHash in ( 
<cfqueryparam cfsqltype="cf_sql_varchar" 
value="#ValueList(hashTableLatest.imageHash)#" list="yes">
)
</cfquery

If possible, you should look for ways to get all the information you need from a single query.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top