Question
Need SQL Query Help
I need help combining two queries into one. This is what I
have now:
<CFQUERY NAME="getInfo" datasource="myDS" BLOCKFACTOR="100">
SELECT
status.status_doc_id,
status.date_accepted,
status.date_received,
document_main.document_main_doc_type,
document_main.document_main_doc_id,
document_main_account_id,
document_main_company_account_id,
document_main_period_of_report,
users_account.client_name,
users_account.account_type
FROM
status,
document_main, users_account
WHERE
status.filing_status_user_id = '2'
AND status.Statustype = 'Live'
AND status.Currentstatus = 'Accepted'
AND status.status_doc_id = document_main.document_main_doc_id
AND users_account.account_id = document_main.document_main_company_account_id
</CFQUERY>
<CFQUERY NAME="getStuff" datasource="myDS" BLOCKFACTOR="100">
SELECT
users_account.client_name,
FROM
users_account
WHERE
account_id = '#getInfo.document_main_account_id#'
AND account_type = 'Individual'
</CFQUERY>
The problem is that the account_id referred to in the users_account table can be either a Company or an Individual. So in my html table the output would list both. A co-worker suggested a UNION ALL and to alias the client_name fields. But that query seems to ignore the alias after the union.
Can anyone help me out?
<CFQUERY NAME="getInfo" datasource="myDS" BLOCKFACTOR="100">
SELECT
status.status_doc_id,
status.date_accepted,
status.date_received,
document_main.document_main_doc_type,
document_main.document_main_doc_id,
document_main_account_id,
document_main_company_account_id,
document_main_period_of_report,
users_account.client_name,
users_account.account_type
FROM
status,
document_main, users_account
WHERE
status.filing_status_user_id = '2'
AND status.Statustype = 'Live'
AND status.Currentstatus = 'Accepted'
AND status.status_doc_id = document_main.document_main_doc_id
AND users_account.account_id = document_main.document_main_company_account_id
</CFQUERY>
<CFQUERY NAME="getStuff" datasource="myDS" BLOCKFACTOR="100">
SELECT
users_account.client_name,
FROM
users_account
WHERE
account_id = '#getInfo.document_main_account_id#'
AND account_type = 'Individual'
</CFQUERY>
The problem is that the account_id referred to in the users_account table can be either a Company or an Individual. So in my html table the output would list both. A co-worker suggested a UNION ALL and to alias the client_name fields. But that query seems to ignore the alias after the union.
Can anyone help me out?
