I'm trying to use Query of Queries based on two separate queries but I'm not getting the result I want. I would consider myself beginner in both SQL and Coldfusion. I'm using Coldfusion 2016 and SQL Server 2012.
Initial request: Give me the name of all applicants whose fee was waived and scheduled an audition.
dsn1.table1 - applicant table
dsn1.table2 - audition table
<cfquery name="getApplicants" datasource="dsn1">
SELECT dbo.table1.STU_ID, dbo.table1.NAME, dbo.table1.FEE_STATUS
FROM dbo.table1, dbo.table2
WHERE (dbo.table1.STU_ID = dbo.table2.STU_ID) AND FEE_STATUS = 'WAIVED'
</cfquery>
THIS WORKS!
Follow-up request: Some applicants did not know their fees were waived so they still went through the payment process. Give me all the applicants that had their fees waived AND scheduled an audition AND did not pay.
dsn2.table3 - contains the payment information. There are multiple entries for an applicant (STU_ID) that timestamps their application process. Sample:
John Doe 123456789 - TENTATIVE - timestamp1 123456789 - PAID - timestamp2 123456789 - EMAILED - timestamp3 123456789 - FINALIZED - timestamp4 Jane Doe 234567895 - TENTATIVE - timestamp1 234567895 - TENTATIVE - timestamp2 234567895 - TENTATIVE - timestamp3 234567895 - CUSTOMER CANCELLED BEFORE PROCESSING PAYMENT - timestamp4 John Smith 345678951 - TENTATIVE - timestamp1 345678951 - TENTATIVE - timestamp2 345678951 - TENTATIVE - timestamp3 345678951 - TENTATIVE - timestamp4 345678951 - PAID - timestamp5 345678951 - FINALIZED - timestamp6 345678951 - EMAILED - timestamp7
My approach was to get the non-payees first:
<cfquery name="getNonPayees" datasource="dsn2">
SELECT dbo.table3.STU_ID, dbo.table3.PAYMENT_STATUS
FROM dbo.table3
WHERE dbo.table3.PAYMENT_STATUS <> 'PAID'
</cfquery>
THIS WORKS!
After that, I was going to use Query of queries to match the results from getApplicants and getNonPayees:
<cfquery dbtype="query" name="QofQ">
SELECT getApplicants.NAME
FROM getApplicants, getPaymentStatus
WHERE getApplicants.STU_ID = getPaymentStatus.STU_ID
</cfquery>
ERROR: The select column reference [getApplicants.NAME] is not found in table [getApplicants].
<cfquery dbtype="query" name="QofQ">
SELECT DISTINCT getApplicants.NAME
FROM getApplicants, getPaymentStatus
WHERE getApplicants.STU_ID = getPaymentStatus.STU_ID
</cfquery>
ERROR: The select column reference [getApplicants.NAME] is not found in table [getApplicants].
<cfquery dbtype="query" name="QofQ">
SELECT *
FROM getApplicants, getPaymentStatus
WHERE getApplicants.STU_ID = getPaymentStatus.STU_ID
</cfquery>
or
<cfquery dbtype="query" name="QofQ">
SELECT NAME
FROM getApplicants, getPaymentStatus
WHERE getApplicants.STU_ID = getPaymentStatus.STU_ID
</cfquery>
No error but I get zero records for the QofQ. Please advise. Thank you!