Skip to main content
Inspiring
April 25, 2009
Question

Common from 4 query results

  • April 25, 2009
  • 1 reply
  • 1226 views

Hi All,

Is there any easy way to get the common records from a dynamic number of query results. I mean I want to get like intersect in sql... the query results will be stored like recordset1,recordset2,recordset3.....

Please help!!!

This topic has been closed for replies.

1 reply

Inspiring
April 25, 2009

I've never tried an intersect query of queries, but this might work

<cfquery dbtype = "query">

<cfloop list = "#querylist# index = "thequery">

select id from #thequery#

intersect

</cfloop>

select id from #ListFirst(querylist)#

balumohanAuthor
Inspiring
April 27, 2009

Hi Dan,

I think we cant use INTERSECT for QoQ. Is there any other alternative??

Inspiring
April 27, 2009

<cfquery dbtype = "query">

select id from #querylist#

where 1 = 1

<cfloop from = "1" to = "#listlen(querylist)# - 1" index = "i">

and #listgetat(querylist, i)#.id = #listgetat(querylist, i + 1)#.id

</cfloop>