473,788 Members | 2,811 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple level nested Corelated query

My multiple level nested corelated query is not fetching correct
result. It work fine on small set of data, but fails on larger set of
data. Any clue?

Explaining data storing and discussing design would be tough for me
here, still to show you how complex I have created my life, here is the
query:

select
(
SELECT Top 1 RowNSBranchID FROM AssoExtBranchTo NSBranchMstM AM
-- MMM
WHERE AM.RowExtSysID IN
(
SELECT RowID FROM ExternalSystemM stM WHERE ExtSysID =
(
SELECT ExtSysID FROM ExternalSystemM stM WHERE SF = 'Active' AND
RowID =
(
SELECT MAX(RowID) FROM ExternalSystemM stM WHERE MCStatus = 2 AND
ExtSysCode = UM.SystemCode
)
)
)
AND RowExtBranchID IN
(
SELECT RowID FROM ExternalBranchM stM
WHERE ExtBranchID =
(
SELECT ExtBranchID FROM ExternalBranchM stM
WHERE ROWID =
(
SELECT RowID FROM ExternalBranchM stM
WHERE ROWID =
(
SELECT MAX(ROWID) FROM ExternalBranchM stM WHERE MCStatus = 2 AND
ExtBranchCode = UM.UpBranchCode
AND RowExtSysID IN
(
SELECT RowID FROM ExternalSystemM stM WHERE ExtSysID =
(
SELECT ExtSysID FROM ExternalSystemM stM WHERE SF = 'Active' AND
RowID =
(
SELECT MAX(RowID) FROM ExternalSystemM stM WHERE MCStatus = 2
AND ExtSysCode = UM.SystemCode
)
)
)
)
AND (SF = 'Active')
)
)
)
AND AM.SF = 'Active'
order by AssoID desc,TrackID desc
) nsbranchid, UM.*

from
TmpInProcessDat a062005MstM UM

Sep 30 '05 #1
5 6411
On 30 Sep 2005 04:11:34 -0700, Zero.NULL wrote:
My multiple level nested corelated query is not fetching correct
result. It work fine on small set of data, but fails on larger set of
data. Any clue?

Explaining data storing and discussing design would be tough for me
here, still to show you how complex I have created my life, here is the
query:

(snip)

Hi Zero.NULL,

Wow! I mean, like, WOW!!!!

Sheesh, you sure know how to make simple things complicated.
After staring in amazement at this code -no, make that: this disaster
waiting to happen- for a while, I can only conclude that I'm very sure
that it's possible to simplify this code considerably. But not without
knowing more. At the very least, please post the table structure of all
tables included in the query, posted as CREATE TABLE statements. You can
omit columns that are irrelevant for the query, but do include all
constraints (esp. primary keys, unique, nullability, and foreign keys
are very important).

If possible, include some rows of sample data (as INSERT statements) to
help clarify what the query is supposed to do, and/or a briefe
explanation of the business problem you're trying to solve.

Check out www.aspfaq.com/5006 for more details on the best ways to aks
for help in these groups.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Sep 30 '05 #2
Hugo,

I accept your critisism in this case, as I have already accepted that I
have made my life complicated. I think you can give your valuable
comment on this. I will construct my design points to post here and
will discuss with you soon on this.

Oct 3 '05 #3
On 2 Oct 2005 23:07:33 -0700, Zero.NULL wrote:
Hugo,

I accept your critisism in this case, as I have already accepted that I
have made my life complicated. I think you can give your valuable
comment on this. I will construct my design points to post here and
will discuss with you soon on this.


Hi Zero.NULL,

Re-reading my message, I feel that I have to apologize. I tried to get a
message across, but I chose the wrong tone. What can I say? It was
friday, and it was late at night - but still. I now wish I had re-read
my message before clicking the Send button.

I'm looking forward to your next post - I hope I can help you sort
things out and improve your code!

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Oct 3 '05 #4
Hi Hugo,
As always you are being a gentleman and willing to provide
help. The above query can be converted into an inner join.
Something like this :--
Select * From EmpMst Where deptid in
( Select deptid from deptmst where deptname='acc')
-----------------
into This ----
--------------
Select * From EmpMst EM
Inner Join DeptMst DM On Dm.deptid = EM.deptid and DM.deptname='ac c'

I have one problem while optimizing the sql query .For a few rows the
query works perfectly ,but as the number of rows increases it works but
gives wrong result.
I am using nested queries W/O aliasing . So what I assume is that Query
Optimizer is trying to flatten the query (converting it into joins)
and in the process ,because of no Alias Name takes a long time .

What might be the reasons for performance debacle? Following is what I
am using
1. Views (using *) ----------
2. Indexing (Clustered)
3. History Data (2 Billion Rows)
4. No Indexed views
5. Scalar Functions ( a bit For format Checking like All
alphabets,digit s etc)
6. No Cursor
7. Updating a permanent temp table for intermediate results.

With Warm regards
Jatinder Singh

Oct 4 '05 #5
On 4 Oct 2005 01:33:08 -0700, jsfromynr wrote:
Hi Hugo,
As always you are being a gentleman and willing to provide
help. The above query can be converted into an inner join.
Something like this :--
Select * From EmpMst Where deptid in
( Select deptid from deptmst where deptname='acc')
-----------------
into This ----
--------------
Select * From EmpMst EM
Inner Join DeptMst DM On Dm.deptid = EM.deptid and DM.deptname='ac c' (snip)

Hi Jatinder,

My apologies for the delayed reply. Real life and other obligations have
been interfering.

The two queries above are not exactly equivalent.

First, the SELECT * (which should never be used in production code,
unless as part of an EXISTS subquery) will produce more columns in the
second query.

Second, the second query might also produce more rows. This will NOT
happen if you have a PRIMARY KEY or UNIQUE constraint on DeptMst.DeptID,
but it will happen if you have no such constraint. If there are three
rows in DeptMst with the same DeptID value, then each row from EmpMst
with that value in EmpMst.DeptID will be tripled in the second query; it
will still be output only once in the first.

I have one problem while optimizing the sql query .For a few rows the
query works perfectly ,but as the number of rows increases it works but
gives wrong result.
If the explanation above does not apply, then I'd have to see a repro
script in order to comment. See further below.

I am using (...)

(snip)

The description of your problem is too vague for me to comment on.
Please post actual table structures (as CREATE TABLE statements,
including all constraints and properties but excluding irrelevant extra
columns), some rows of sample data (as INSERT statements - and not all 2
billioin of'em, please - just enough to demonstrate the situation), the
actual query you've been using, the output you needed and the output you
actually got.

Also check out www.aspfaq.com/5006.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Oct 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
9030
by: Alban Hertroys | last post by:
Oh no! It's me and transactions again :) I'm not really sure whether this is a limitation of psycopg or postgresql. When I use multiple cursors in a transaction, the records inserted at the start of the transaction aren't visible to those later on in that transaction (using a different cursor). Attached is a simplified example (the except's are a bit blunt, I know) of what I'm trying to do. In reality, the different cursors are...
7
4004
by: Kannan | last post by:
Hello, I have a situation which would essentially use a co-related subquery. I am trying to avoid using a co-related subquery due to its slow performanc and use a join statement instead. Here is what I am trying to do: Tables: ======== Limit
7
6218
by: Rick Caborn | last post by:
Does anyone know of a way to execute sql code from a dynamically built text field? Before beginning, let me state that I know this db architecture is built solely for frustration and I hope to make it better soon. Unfortunately, there is never a non-crucial time in which we can do an upgrade, so we are stuck for now. Point 1: There are multiple tables: students, courses, cross-reference
11
5320
by: Mike | last post by:
Looking to find any information on how to properly configure multiple instances of DB2. This is on Win2k db2 ver 7.2. I am basically looking for information on how the multiple instance settings should configured to work, how memory is shared or not, etc. I can not seem to find any good links to this information. Thanks, Mike
3
3305
by: Br | last post by:
I'm going to go into a fair bit of detail as I'm hoping my methods may be of assistance to anyone else wanting to implement something similar (or totally confusing:) One of systems I've developed has three levels of security. Admins - can see all records Manager - can only see records based on an organisation structure held in a table (simple tree structure) Employee - can only see own records
3
1840
by: jonceramic | last post by:
Hi all, I'm not sure exactly what words to use or how to Google this. (I keep coming up with BOL links.) So, I'm going to ask the group for a starting point or proper terms to even describe what I'm doing. Is this a "thread handler? Or a "hierarchy tree" or what? ----------------------- Basically, I'm working on a project that will be a task and project tracking tool. What I've been asked to do is provide functionality
9
4397
by: P3Eddie | last post by:
Hello all! I don't know if this can even be done, but I'm sure you will either help or suggest another avenue to accomplish the same. My problem may be a simple find duplicates / do something with only one of the duplicates issue, but I got to the point where an update query with a nested select subquery would work wonderfully, if only it would work! I have several fields in a master Access 2000 table, some of which are id, fname,...
0
2189
by: xtopia | last post by:
Hi Guys I'm a novice access VBA programmer. I’m trying to write a nested query to explode the bill of material. But the BOM table has more than 20 levels. It’s really redundant and annoying to write all those nested queries in access. my question is, how do I approach this problem to solve it using VBA. I’ve seen so many vba codes online, but I don’t seem to understand it well enough to apply it in my situation. the fields in the BOM...
1
6083
by: xtopia | last post by:
Hi Guys I'm a novice access VBA programmer. I’m trying to write a nested query to explode the bill of material. But the BOM table has more than 20 levels. It’s really redundant and annoying to write all those nested queries in access. my question is, how do I approach this problem to solve it using VBA. I’ve seen so many vba codes online, but I don’t seem to understand it well enough to apply it in my situation. the fields in the BOM...
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10364
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9967
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.