IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New SQL Subqueries
I'm not quite sure what you mean by "multi-level selects", but I suspect you mean correlated subqueries. Similar to sentence fragments.

Useful device. Will be used. More later.

Like most syntactic outliers, subqueries are useful. Used judiciously. The can simplify some convoluted coding, reduce extra steps, and occasionally improve performance. They can also to the reverse of all in spades.

My usual preference is to keep subqueries restricted to a depth of one, possibly two in exceptional cases. Anything more than this and I start abstracting out the queries, either as views or additional CREATE TABLE queries (use your workspace for these). The set nature of SQL means that, if you can work out the logic and parameters of the queries themselves, you can replace a subquery with the equivalent table or view.

I have to admit complete ignorance of PL/SQL, but I've used SQL extensively in generating reports with SAS, where many intermediate steps can often be saved with some only mildly convoluted query logic.
--
Karsten M. Self [link|mailto:kmself@ix.netcom.com|kmself@ix.netcom.com]
What part of "gestalt" don't you understand?
New Maybe not (subqueries that is)
I've seen queries similar to

select d.(stuff) from a, b, c, d
where a.(stuff) = b.(stuff) and b.(stuff) = c.(stuff) and c.(stuff) = d.(stuff)

and have seen query "optimizers" make stupid decisions about what to select from where and when. This is particularly evident when you upgrade from one version of a database to another; often times they've "improved" the optimizer enough to shoot the hell out of your carefully crafted queries that worked with the old one.

(Most databases seem to have pathetic query analyzers and diagnostics, but I digress.)

Not that this helps in this particular problem. I ran into a report converting tool ("automatically" converted from one 4GL with one flavor of database selection syntax to another) that did some Gawdawful stuff to the SQL, but because there were so many reports it wasn't possible to go through and optimize each report. I have every reason to think that those reports (in the tortured SQL version) still exist.
"Beware of bugs in the above code; I have only proved it correct, not tried it."
-- Donald Knuth
     I Dunno where this belongs, so I'm putting it here - (broomberg) - (12)
         Book a farewell lunch for the President? - (Meerkat)
         You need the president on side. - (static)
         Don't start over... - (pwhysall) - (1)
             That advice is optimistic - (ben_tilly)
         An embarassment of riches - (jb4)
         Maybe candidate for top-down refactoring - (drewk)
         SQL Subqueries - (kmself) - (1)
             Maybe not (subqueries that is) - (wharris2)
         Oracle and PL/SQL tips - (SpiceWare)
         Bang! Dodge - whish - (broomberg) - (2)
             Phew. Yay! -NT - (Meerkat)
             Lucky you... - (ben_tilly)

Sittin' on the Group W bench.
137 ms