This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Options for a Subquery Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Options for a Subquery" Watch "Options for a Subquery" New topic

Options for a Subquery

amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 544
I have read that subqueries perform much slower. I would like to know what are the other options available we can consider instead of using subqueries. I have seen 80% subqueries in the Stored procedures which I am accessing in Java.
I remember once we had used Temp table approach to reduce this usage. I am not an expert in Database but occasionally need to write some queries and Stored procedures.


Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63870

Before diving off into alternatives, perhaps it would be best to ascertain that sub-queries are actually a problem? Just reading it somewhere doesn't mean it's a real issue, and even if they are in certain circumstances, it's best to verify that something is an actual problem in your environment before flying off the handle.

[Asking smart questions] [About Bear] [Books by Bear]
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 544
Hi Bear,
Thanks for your reply. I agree with whatever you have said. I just wanted to know whether this kind of topic is available in the HF SQL.
Thanks once again,
Paul Campbell
Ranch Hand

Joined: Oct 06, 2007
Posts: 338
Poorly written queries always perform poorly.

Sub-queries are a necessary part of set processing. Learning to write quality queries entails you learn how to write effective sub-queries.
Lynn Beighley
Ranch Hand

Joined: Sep 12, 2007
Posts: 82
In HF SQL, we deal with presenting some subqueries as joins, and vice versa, but do not offer an opinion on the difference in performance.

Lynn Beighley<br />Author, Head First SQL
I agree. Here's the link:
subject: Options for a Subquery
It's not a secret anymore!