Skip to main content
Participant
April 26, 2010
Question

Database Query Output - Suggestions Please!

  • April 26, 2010
  • 1 reply
  • 862 views

Hi guys,

I'm a beginner at Coldfusion and I'd like your advice on what to do with an issue I have.

I currently have 3 related database queries that return results from 3 different tables in my database. I'd like the listed output from the second query to feature the name column of its specific row (these are 'eevent' in the query 'events' and 'Nname' in the Query 'artists'). Currently I'm only able to display the ID column from the second query. For example, I'd like the name from the 'artist' query rather than simply the 'artistID' from the 'applied' query.

I'm unsure of how to go about this and would greatly appreciate any suggestions anyone might have?

Here is my code:

<!--- THIS FINDS OUT THE PROMOTERS EVENTS --->

<cfquery name="events" datasource="071907cs07to">
SELECT eventID, eevent
FROM   Event
WHERE  epromoterID = #SESSION.auth.PromoterID#
</cfquery>

<!--- THEN THE APPLIED LIST FROM THOSE EVENTS --->

<cfquery name="applied" datasource="071907cs07to">
SELECT eventID, artistID
FROM   Applied
WHERE  eventID IN (#ValueList(events.eventID)#)
</cfquery>

<!--- THEN THE ARTIST NAMES FROM THOSE APPLICATIONS --->

<cfquery name="artists" datasource="071907cs07to">
SELECT Nname, artistID
FROM   Artist
WHERE  artistID IN (#ValueList(applied.artistID)#)
</cfquery>

<table class="main">
<cfoutput query="applied">

<tr>
<td>

'#artistID#'

would like to play:

#eventID#.
</td>

</tr>
</cfoutput>
</table>

Currently, the code is returning the ID numbers - I'd like to know if it's possible to output the names of the artists and events from the other two queries instead?

Thanks,

Tom

This topic has been closed for replies.

1 reply

tclaremont
Inspiring
April 26, 2010

#Applied.ArtistID# will return the ArtistID content from the Applied query.

#Artists.ArtistID# will return the ArtistID content from the Artists query.

Get the idea?

Participant
April 26, 2010

That's not what I mean. The returned results have to be those from the second query. But I'd like these results to involve the related names rather than the ID numbers.

tclaremont
Inspiring
April 26, 2010

I see.

Do a quick websearch on queries and inner joins. This will allow you to JOIN the table that includes the actual name, which is linked to the number.

"Teach Yourself SQL in 30 minutes" is a great book, and a quick read. It will have you creating great queries in minutes.