looking for better way | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

looking for better way

hi friends, I have a stored procedure (sp1) that contains 3 sub queries q1, q2, q3 .
these sub queries are ratherly similar to each other and differ only in a where condition
for example: q1::
Select *
From t1 inner join t2 inner join t3 on t1.f11 = t2.f22 on t2.f22 = t3.f33
Where t3.f34 = ‘a’ q2:
Select *
From t1 inner join t2 inner join t3 on t1.f11 = t2.f22 on t2.f22 = t3.f33
Where t3.f34 = ‘b’
q3::
Select *
From t1 inner join t2 inner join t3 on t1.f11 = t2.f22 on t2.f22 = t3.f33
Where t3.f34 = ‘c’
of course i connect these sub queries at the end of my stored procedure in order to get final results….
Now, my question is: Is there any better way of getting the final results? If yes How? Thank you very much Sonia
Cant you use this? Select * — explicitely specify the required columns
From t1 inner join t2 inner join t3 on t1.f11 = t2.f22 on t2.f22 = t3.f33
Where t3.f34 in(‘a’,’b’,’c’)
Madhivanan Failing to plan is Planning to fail
Madhivanan has demonstrated the best way to pull what you were looking for in this case. Should you come across other scenarios where you are selecting 5 like fields and can’t do a single query to do it, you should check out the UNION clause in Books on line. It allows you to execute different queries and then take a UNION of the results so they are joined together in 1 result set that is retrieved. Be sure to pay attention when you are reading to the difference between UNION and UNION ALL. Best of luck,
Dalton
]]>