Subqueries Workaround
Teradata Teradata Discussion Forums Teradata.com Discussion Forum
Visit Teradata.com
Home       Guidelines    Member List
Welcome Guest ( Login | Register )
        


This online forum is for user-to-user discussions of Teradata products, and is not an official customer support channel for Teradata. If you require direct assistance, please contact Teradata support.


Subqueries Workaround Expand / Collapse
Author
Message
Posted 9/2/2009 12:01:57 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 9/10/2009 3:59:11 PM
Posts: 2, Visits: 13
Hi,



I noticed that I can’t do sub queries in Teradata.



For example:

Select patient_name

Patient_age,

Patient_weight,

(Select Count(*) from drug_taken WHERE drug_name=”Warfarin” patient_id=10) CountWarfarin,

(Select Count(*) from drug_taken WHERE drug_name=”Heprin” patient_id=10) CountHeprin

FROM patient

WHERE patient_id=10



So what is the workaround for this? Where I don’t have to create a stored procedure.



Thank you,

-Tesh
Post #16728
Posted 9/7/2009 6:24:02 AM
Forum Member

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member

Group: Forum Members
Last Login: 10/30/2009 6:28:19 AM
Posts: 34, Visits: 117
It's not that Sub-queries are not allowed in Teradata. It has to be handelled properly.
Check - if the following query is giving the same result or not.

SELECT
PATIENT_NAME
,PATIENT_AGE
,PATIENT_WEIGHT
,COUNTWARFARIN.CNT1
,COUNTHEPRIN.CNT2

FROM
PATIENT
,(SELECT COUNT(*) CNT1 FROM DRUG_TAKEN WHERE DRUG_NAME = 'WARFARIN' AND PATIENT_ID=10) COUNTWARFARIN
,(SELECT COUNT(*) CNT2 FROM DRUG_TAKEN WHERE DRUG_NAME = 'HEPRIN' AND PATIENT_ID=10) COUNTHEPRIN
WHERE
PATIENT_ID=10
;


Other Query Experts need to interfere and answer - Cummon!!!

Regards,
ANIMESH DUTTA
Post #16776
Posted 9/25/2009 4:51:50 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 10/21/2009 4:47:49 PM
Posts: 7, Visits: 29
The above reply is quite a alternative, else a volatile table can be used here.
Post #16943
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 0 ( 0 guests, 0 members, 0 anonymous members )
No members currently viewing this topic.


All times are GMT -5:00, Time now is 10:32pm

Powered By InstantForum.NET v4.1.4 © 2009
Execution: 0.125. 9 queries. Compression Disabled.