473,387 Members | 1,481 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

subquery/nested query - do I need to redesign my query or my database?

I administer a mechanical engineering database. I need to build a
query which uses the results from a subquery as its input or
criterion.

I am attempting to find all of the component parts of which a part may
be composed. I have a table of parts and their subparts. The problem
is that each of those subparts may be composed of smaller component
parts. The subpart would then be listed in the Part field linked to
each of its subparts in the Subpart field. I need to build a query
which finds all of the subparts to the 4th degree.

The query I built has had queer results, so I am doing something
wrong. I failed to write an SQL statement that nests the subquery
properly. When using the QueryBuilder and putting the subquery in the
table field I get problems even before trying to link the result of
the first query to another field. It displays the result of the first
query once for each row of the table. When I run the subquery as its
own query the result displays only once as expected.

I have researched this in the Access 2002 bible and over the net
without finding help. Suggestions?
Nov 12 '05 #1
7 2343
I can help!

If you would like my help, contact me at the email address below.

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
"K. Crothers" <k_********@yahoo.com> wrote in message
news:88**************************@posting.google.c om...
I administer a mechanical engineering database. I need to build a
query which uses the results from a subquery as its input or
criterion.

I am attempting to find all of the component parts of which a part may
be composed. I have a table of parts and their subparts. The problem
is that each of those subparts may be composed of smaller component
parts. The subpart would then be listed in the Part field linked to
each of its subparts in the Subpart field. I need to build a query
which finds all of the subparts to the 4th degree.

The query I built has had queer results, so I am doing something
wrong. I failed to write an SQL statement that nests the subquery
properly. When using the QueryBuilder and putting the subquery in the
table field I get problems even before trying to link the result of
the first query to another field. It displays the result of the first
query once for each row of the table. When I run the subquery as its
own query the result displays only once as expected.

I have researched this in the Access 2002 bible and over the net
without finding help. Suggestions?

Nov 12 '05 #2
"K. Crothers" <k_********@yahoo.com> wrote in message
news:88**************************@posting.google.c om...
I administer a mechanical engineering database. I need to build a
query which uses the results from a subquery as its input or
criterion.

I am attempting to find all of the component parts of which a part may
be composed. I have a table of parts and their subparts. The problem
is that each of those subparts may be composed of smaller component
parts. The subpart would then be listed in the Part field linked to
each of its subparts in the Subpart field. I need to build a query
which finds all of the subparts to the 4th degree.

The query I built has had queer results, so I am doing something
wrong. I failed to write an SQL statement that nests the subquery
properly. When using the QueryBuilder and putting the subquery in the
table field I get problems even before trying to link the result of
the first query to another field. It displays the result of the first
query once for each row of the table. When I run the subquery as its
own query the result displays only once as expected.

I have researched this in the Access 2002 bible and over the net
without finding help. Suggestions?

Post some information about your table structure(s) with some sample data
and the output you need and we will help.
Nov 12 '05 #3
"Steve" <sp**@nospam.spam> wrote in message
news:No*******************@newsread3.news.atl.eart hlink.net...
I can help!

If you would like my help, contact me at the email address below.

hey steve, any reason why you don't want to share your help with the rest of
the group?
Nov 12 '05 #4
CDB
Mr K Crothers, I would be cautious about seeking help from someone who is so
desperate for work that he will blatantly flout the rules for this
newsgroup. Questionable ethics.

Clive Bolton
"Steve" <sp**@nospam.spam> wrote in message
news:No*******************@newsread3.news.atl.eart hlink.net...
I can help!

If you would like my help, contact me at the email address below.

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
"K. Crothers" <k_********@yahoo.com> wrote in message
news:88**************************@posting.google.c om...
I administer a mechanical engineering database. I need to build a
query which uses the results from a subquery as its input or
criterion.

I am attempting to find all of the component parts of which a part may
be composed. I have a table of parts and their subparts. The problem
is that each of those subparts may be composed of smaller component
parts. The subpart would then be listed in the Part field linked to
each of its subparts in the Subpart field. I need to build a query
which finds all of the subparts to the 4th degree.

The query I built has had queer results, so I am doing something
wrong. I failed to write an SQL statement that nests the subquery
properly. When using the QueryBuilder and putting the subquery in the
table field I get problems even before trying to link the result of
the first query to another field. It displays the result of the first
query once for each row of the table. When I run the subquery as its
own query the result displays only once as expected.

I have researched this in the Access 2002 bible and over the net
without finding help. Suggestions?


Nov 12 '05 #5
"John Winterbottom" <as******@hotmail.com> wrote in message news:<2g************@uni-berlin.de>...
"K. Crothers" <k_********@yahoo.com> wrote in message
news:88**************************@posting.google.c om...
I administer a mechanical engineering database. I need to build a
query which uses the results from a subquery as its input or
criterion.

I am attempting to find all of the component parts of which a part may
be composed. I have a table of parts and their subparts. The problem
is that each of those subparts may be composed of smaller component
parts. The subpart would then be listed in the Part field linked to
each of its subparts in the Subpart field. I need to build a query
which finds all of the subparts to the 4th degree.

The query I built has had queer results, so I am doing something
wrong. I failed to write an SQL statement that nests the subquery
properly. When using the QueryBuilder and putting the subquery in the
table field I get problems even before trying to link the result of
the first query to another field. It displays the result of the first
query once for each row of the table. When I run the subquery as its
own query the result displays only once as expected.

I have researched this in the Access 2002 bible and over the net
without finding help. Suggestions?

Post some information about your table structure(s) with some sample data
and the output you need and we will help.


SAMPLE DATA

Child Part Table

PartNumber ChildPart (keyID)
1000 1100
1000 1200
1000 1300
1100 1110
1100 1120
1200 1250
1200 1270
1250 1255
2000 2500
2000 2800
3000 3200
etc.

(ChildParts do not follow this numbering convention.)

Part Table

PartNumber (keyID)
1000
1100
1110
1120
1200
1250
1255
1270
1300
2000
2500
2800
3000
3200
etc.

Query Criterion: '1000'
Query Output:
1100
1200
1300
1110
1120
1250
1270
1255

Because it does not pertain to the primary problem, I have omitted
that ChildParts appear as numbers with a decimal place (XXXX.X) that
need to be rounded off to integers to find their ChildParts.

Thanks for any suggestions!
Nov 12 '05 #6
"K. Crothers" <k_********@yahoo.com> wrote in message
news:88**************************@posting.google.c om...
I have researched this in the Access 2002 bible and over the net
without finding help. Suggestions?

Post some information about your table structure(s) with some sample data and the output you need and we will help.


SAMPLE DATA

Child Part Table

PartNumber ChildPart (keyID)
1000 1100
1000 1200
1000 1300
1100 1110
1100 1120
1200 1250
1200 1270
1250 1255
2000 2500
2000 2800
3000 3200
etc.

(ChildParts do not follow this numbering convention.)

Part Table

PartNumber (keyID)
1000
1100
1110
1120
1200
1250
1255
1270
1300
2000
2500
2800
3000
3200
etc.

Query Criterion: '1000'
Query Output:
1100
1200
1300
1110
1120
1250
1270
1255


If you know you will only ever have four levels you could do something like
this. It's not pretty but it will work.

parameters [partnum] int;
select '' as hierarchy, PartNumber
from Parts
where PartNumber = [partnum]
union all
select '-', ChildPart
from ChildParts
where PartNumber = [partnum]
union all
select '--', c2.ChildPart
from ChildParts c1
inner join ChildParts c2 on c1.ChildPart = c2.PartNumber
where c1.PartNumber = [partnum]
union all
select '---', c3.ChildPart
from
(
ChildParts as c1
inner join ChildParts as c2 on c1.ChildPart = c2.PartNumber
)
inner join ChildParts AS c3 on c2.ChildPart = c3.PartNumber
where c1.PartNumber=[partnum]
order by hierarchy, PartNumber
There are better designs for hieracrchies - detaills of one at
http://www.mvps.org/access/queries/qry0023.htm


Nov 12 '05 #7
"John Winterbottom" <as******@hotmail.com> wrote in message news:<2g************@uni-berlin.de>...
"K. Crothers" <k_********@yahoo.com> wrote in message
news:88**************************@posting.google.c om...
> I have researched this in the Access 2002 bible and over the net
> without finding help. Suggestions?
Post some information about your table structure(s) with some sample data and the output you need and we will help.


SAMPLE DATA

Child Part Table

PartNumber ChildPart (keyID)
1000 1100
1000 1200
1000 1300
1100 1110
1100 1120
1200 1250
1200 1270
1250 1255
2000 2500
2000 2800
3000 3200
etc.

(ChildParts do not follow this numbering convention.)

Part Table

PartNumber (keyID)
1000
1100
1110
1120
1200
1250
1255
1270
1300
2000
2500
2800
3000
3200
etc.

Query Criterion: '1000'
Query Output:
1100
1200
1300
1110
1120
1250
1270
1255


If you know you will only ever have four levels you could do something like
this. It's not pretty but it will work.

parameters [partnum] int;
select '' as hierarchy, PartNumber
from Parts
where PartNumber = [partnum]
union all
select '-', ChildPart
from ChildParts
where PartNumber = [partnum]
union all
select '--', c2.ChildPart
from ChildParts c1
inner join ChildParts c2 on c1.ChildPart = c2.PartNumber
where c1.PartNumber = [partnum]
union all
select '---', c3.ChildPart
from
(
ChildParts as c1
inner join ChildParts as c2 on c1.ChildPart = c2.PartNumber
)
inner join ChildParts AS c3 on c2.ChildPart = c3.PartNumber
where c1.PartNumber=[partnum]
order by hierarchy, PartNumber
There are better designs for hieracrchies - detaills of one at
http://www.mvps.org/access/queries/qry0023.htm


I will attempt to implement this shortly, but I wanted to write,
"Thank you", immediately. I downloaded the BOM database. The mvps.org
site helped me answer another question as well. Hopefully, I will be
able to contribute at some point.

Thanks again.

Kevin
Nov 12 '05 #8

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

Similar topics

6
by: Dan Evans | last post by:
Hi, Can anyone help me on a little problem I am having with some SQL - in particular on a subquery. I am setting up a database in Access for a voluntary group which runs
2
by: lev | last post by:
CREATE TABLE . ( NULL , , (44) ) ID is non-unique. I want to select all IDs where the last entry for that ID is of type 11.
7
by: Andrew Mayo | last post by:
Here's a really weird one for any SQL Server gurus out there... We have observed (SQL Server 2000) scenarios where a stored procedure which (a) begins a transaction (b) inserts some rows into...
1
by: LazyAnt | last post by:
Does DB2 process "ALL" subquery by "nested iteration" strategy, or using its own special algorithm? For example, assume r(A, B, C) and s(D, E, F) are two relations, consider the following query:...
8
by: Venkata C | last post by:
Hi! Does anyone here know of a way to goad DB2 into converting a correlated subquery to a non-correlated one? Does DB2 ever do such a conversion? We have a query of the form SELECT .. FROM A...
4
by: Kenny G | last post by:
Below is a query that I currently have. I need to produce a subquery so that the top five of the CodeCount is returned. I appreciate your help. SELECT .PX_SURGEON, .PX_CODE, Count(.PX_CODE)...
8
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a...
5
by: steven.fafel | last post by:
I am running 2 versions of a correlated subquery. The two version differ slightly in design but differ tremendously in performance....if anyone can answer this, you would be awesome. The "bad"...
1
by: jcf378 | last post by:
Hi all-- Does anyone have any insight as to how I might create a search form that allows a user to select criteria based on any related table in the whole database. The search form I have now only...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.