Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question on DISTINCT in a looped query

Status
Not open for further replies.

goldensunrise

Programmer
Nov 22, 2000
18
Why does this not work?

<CFLOOP INDEX=&quot;Loop&quot; FROM=&quot;1&quot; TO=&quot;9&quot;>
<CFQUERY NAME=&quot;Loop&quot; DATASOURCE=&quot;Project&quot;>
SELECT DISTINCT Catagory.CatagoryID, Catagory.Catagory, SiteListing.*
FROM SiteListing, Catagory
WHERE (SiteListing.CatagoryID = #Loop#) AND Catagory.CatagoryID = SiteListing.CatagoryID
</CFQUERY>
<CFOUTPUT QUERY=&quot;Loop&quot;>
#Catagory#
(#Loop.RecordCount#)<BR>
</CFOUTPUT>
</CFLOOP>
 
this is really weird :
&quot;WHERE (SiteListing.CatagoryID = #Loop#) AND Catagory.CatagoryID = SiteListing.CatagoryID&quot;

if you wanted all the catagories
WHERE Catagory.CatagoryID = SiteListing.CatagoryID

if you wanted only the 9 first catagories
WHERE SiteListing.CatagoryID < 10 AND Catagory.CatagoryID = SiteListing.CatagoryID

 
Well... I'd definitely say you wouldn't want to loop over a query nine times if there's another solution to get the same results in one pass...

From what I can tell, it looks like you probably want something like:
Code:
<CFQUERY NAME=&quot;Loop&quot; DATASOURCE=&quot;Project&quot;>
  SELECT DISTINCT 
    Catagory.CatagoryID, 
    Catagory.Catagory, 
    SiteListing.*
  FROM SiteListing, Catagory
  WHERE (SiteListing.CatagoryID > 10) AND
    Catagory.CatagoryID = SiteListing.CatagoryID
</CFQUERY>

<CFOUTPUT QUERY=&quot;Loop&quot;>
  #Catagory#
  (#CurrentRow#)<BR>
</CFOUTPUT>
Hope this helps... DarkMan
 
yes i guess that's what goldensunrise wanted to do
except that the >10 is actually <10 but who cares !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top