cfloop two tables

I have cfloop query and I need to add a column from another table into the cfloop. There are similar keys in each table but what is the best way to structure the query output?
aspiegelAsked:
Who is Participating?
 
Scott BennettConnect With a Mentor Manager TechnologyCommented:
just use two loops. Something like this:
<cfquery name="FirstQuery" datasource="DSN">
SELECT something FROM aTable
</cfquery>

<cfquery name="SecondQuery" datasource="DSN">
SELECT somethingelse FROM anotherTable
</cfquery>

<cfloop query="FirstQuery">
      #firstQuery.something#
      <cfloop query="SecondQuery">
            #SecondQuery.somethingelse#
      </cfloop>
</cfloop>


or if your second query depends will be based on data from the first query:

<cfquery name="FirstQuery" datasource="DSN">
SELECT something FROM aTable
</cfquery>

<cfloop query="FirstQuery">
      #firstQuery.something#
      <cfquery name="SecondQuery" datasource="DSN">
      SELECT somethingelse FROM anotherTable where something = '#firstQuery.something#'
      </cfquery>
      <cfloop query="SecondQuery">
            #SecondQuery.somethingelse#
      </cfloop>
</cfloop>

how you sturcture the loops depends on the data and how you want it to be presented.
0
 
Scott BennettManager TechnologyCommented:
you question is really vague so if that doesn't give you an idea of what to do, then give a sample of the queries you are doing and how you want to display the data.
0
 
aspiegelAuthor Commented:
That worked great. Thanks for your help and quick response.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.