Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
cplusplus
Aged Yak Warrior
567 Posts |
Posted - 2012-11-27 : 16:53:54
|
I have the following two select queries, i want to use teh second second in the first query join is it possible:select plan_name from health_plan where health_plan.health_plan_id = E_Plan_R.health_plan_id and health_plan.active_ind=1i want to use this query to get health_plan_id which is used in teh above query after equalto sign, is it possible to directly use it there in the above query to make as one single instead of two.select health_plan_id from encntr_plan_reltn where enc.encid= encntr_plan_reltn.encid and priority_seq=1 and active_ind=1and beg_eff_dt > = sysdate(); I am planning to use the above query's as inquery/subquery within a big sql query block where all joins etc already defined and working just want to add the above one.Thank you very much for the help. |
|
cplusplus
Aged Yak Warrior
567 Posts |
Posted - 2012-11-27 : 17:42:43
|
OK got it:(select plan_name from health_plan where health_plan_id =(select health_plan_id from encntr_plan_reltn where enc.encntr_id= encntr_plan_reltn.encntr_id and priority_seq=1 and active_ind=1 and BEG_EFFECTIVE_DT_TM >= sysdate() and rownum < 2) and health_plan.active_ind=1 and rownum < 2) |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2012-11-27 : 18:45:43
|
This might be betterselect plan_name from health_plan hpwhere exists (select * from encntr_plan_reltn r where enc.encntr_id= encntr_plan_reltn.encntr_id and priority_seq=1 and active_ind=1 and BEG_EFFECTIVE_DT_TM >= sysdate() and rownum < 2) and health_plan.active_ind=1 and rownum < 2 and hp.health_plan_id = r.health_plan_idor even just this select hp.plan_name from health_plan hp inner join encntr_plan_reltn r on hp.health_plan_id = r.health_plan_id where enc.encntr_id= encntr_plan_reltn.encntr_id and r.priority_seq=1 and r.active_ind=1 and r.BEG_EFFECTIVE_DT_TM >= sysdate() and r.rownum < 2) and health_plan.active_ind=1 and rownum < 2 )JimEveryday I learn something that somebody else already knew |
|
|
|
|
|