ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
  #1  
Old April 25th, 2004, 12:45 AM
cassjack cassjack is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 2 cassjack User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Help Needed For Complex Inner Join In Coldfusion

Hi,

I'm having a problem retrieving accurate information from an inner join. I am trying to access three database tables for this information.

1. GRADES, which contains Subcategory id (SC_ID), Student id (STU_ID), and grade (GRADE)

2. SUBCATEGORY, which contains Subcategory id (SC_ID), Category id (CAT_ID), and Course id (COURSE_ID)

3. CATEGORY, which contains Category id (CAT_ID) and Course id (COURSE_ID)

I know how to retrieve this information using subqueries but ColdFusion doesn't support subqueries (darn!!) and I am forced to use inner joins. But I am at a complete loss on how to accomplish this. I have been trying different combinations for hours (trust me) and I still can't find a solution. The result I am looking for is to have the query retrieve the correct category name using the course number provided from the previous form, use this category name to find the correct subcategory ids, and find the correct grades using this subcategory id.

Here is the code with the subquery:

<!-- the course number passed from previous form -->

<cfif not isDefined("number")>
<cflocation url="report.cfm">
</cfif>

<!-- retrieves an array of students belonging to the course number -->
<cfset myArray = ArrayNew(2)> <sets up a 2-d array>
<cfquery name="getstudents" dataSource="ternion01">
select STUDENT.STU_ID, STU_LNAME, STU_FNAME from ENROLLMENT, STUDENT where ENROLLMENT.COURSE_ID = "#number#" AND STUDENT.STU_ID = ENROLLMENT.STU_ID
</cfquery>
<!-- retrieves the student information and places this info in array -->
<cfloop query="getstudents">
<cfset myArray[CurrentRow][1] = getstudents.STU_ID>
<cfset myArray[CurrentRow][2] = getstudents.STU_LNAME>
<cfset myArray[CurrentRow][3] = getstudents.STU_FNAME>
</cfloop>

<!-- attempting to query the database for specific categories and their corresponding subcategory grades -->
<!-- using a loop to search for information based on the approprate student defined in the array above -->
<!-- this is where the problem is!! -->
<cfloop index="i" from="1" to="#getstudents.RecordCount#">
<cfquery name="getdata" dataSource="ternion01">
select CATEGORY.CAT_NAME, SUM(GRADE)*(CAT_WEIGHT/100) MYSUM
from CATEGORY, GRADES
where CATEGORY.COURSE_ID = "#number#"
AND STU_ID = "#myArray[i][1]#"
AND GRADES.SC_ID = (select SC_ID from SUBCATEGORY where CAT_ID = (select CAT_ID from CATEGORY where COURSE_ID = "#number#"))
group by CAT_NAME

</cfquery>
<!-- the problem is with the subquery, I am clueless on how to join all this information --> <!-- places this information into the array with the student information -->
<cfloop query="getdata">
<cfset myArray[i][(CurrentRow*2)+2] = getdata.CAT_NAME>
<cfset myArray[i][(CurrentRow*2)+3] = getdata.MYSUM>
</cfloop>
</cfloop>

<!-- used to check contents of the array -->
<cfdump var="#myArray#">

Any help will be much appreciated.

Thanks,
Cassandra

Reply With Quote
  #2  
Old April 25th, 2004, 10:59 AM
kiteless kiteless is online now
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,492 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 18 h 25 m 57 sec
Reputation Power: 44
Cassandra, you are mistaken. When it comes to SQL, ColdFusion handles nothing. All ColdFusion does is forward the SQL statement to a database via a data source connection. If you are having problems getting subqueries to work, it is either a mistake in your code or the fact that your RDBMS does not support subqueries. ColdFusion has nothing to do with it. I have built queries with multiple inline views and multiple levels of nested subqueries to query Oracle 9i databases.

So, if you feel that using subqueries would solve your problem, I'd look into that before trying to cludge around it with inner joins.

Reply With Quote
  #3  
Old April 25th, 2004, 09:43 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 24th Plane (16500 - 16999 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 16,745 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 2 Days 21 h 39 m 34 sec
Reputation Power: 870
cassjack, please do not cross-post

http://forums.devshed.com/showthread.php?t=142412

which one of these two threads do you want to keep? i will delete the other one
__________________
r937.com | rudy.ca

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Help Needed For Complex Inner Join In Coldfusion


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway