whos could be much efficient if I use nestted subquery
, JOINs
Or maybe temp tables
..
another question : in subqueries if i use IN Cl
The two queries are equivalent, and should produce identical plans. It's a misconception that CTEs are compiled only once, providing a performance benefit. Non-recursive CTEs are just syntactic sugar for derived tables/inline views (IMO mistakenly referred to as subqueries).
Secondly, JOINs vs IN/EXISTS can produce different results. JOINs risk duplicated data, if there's two or more supporting records. EXISTS is best used if there are duplicate criteria, because it returns true on the first encounter of the criteria - making it potentially faster than IN or JOIN. There's no data duplication risk when using EXISTS or IN.