473,471 Members | 4,095 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Better query method?

------=_NextPart_000_04B4_01C36308.415CE100
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi all,

Long time reader, first time poster, I hope that I get this right.

I am setting up a database that reflects a relationship between two =
records without using the primary key as the tie between the two. I =
need to make a list of these based on the number of children each has, =
and I am having a problem with the query set up. Currently I have the =
query set up to run at number of users +1, and that doesn't seem to be =
very efficient.

The records are something like this.

user ID number Name Parent

1 John 0
2 Don 1
3 Joe 1
4 Jack 2
5 Jill 4
6 Jane 4
okay, now I need to be able to make a list of the names, with the number =
of children that they have, then sort them in order of how many children =
they have. Basically, I want to make a list that has in numerical order =
the names of the parent, and how many children they have. I hope that =
it makes sense the way that I have described it. I have it working, but =
if my list of parents and children gets long, then it will kill me i =
think. =20

The above list would display as
Name Number of Children
John 2
Jack 2
Don 1
Joe 0
Jill 0
Jane 0

The way that I have it working right now, is I run a query to find out =
the number of records, then I run a query based on the first user (1), =
find all the children that belong to that user and store it in an array, =
then another query based on the second record to discover how many =
children that user has, so on and so forth until the end of the table is =
reached. Then i sort the array based on the number of children, the =
person with the most children goes at the top, and it descends from =
there. As you can see, I am running a query to find out the number of =
records, then a query based on each record. If my table gets to 50,000 =
users then that will be a nightmare I think.

Any help to point me in the right direction would be appreciated, I am =
using MySql 4.x, my local testing server is a Win2k machine, but my web =
server is a Linux box. I am mainly just looking for a concept for the =
better query, not the actual code to write it. I just can't seem to =
think of a better way to structure it.

Thanks!
------=_NextPart_000_04B4_01C36308.415CE100--
Jul 19 '05 #1
0 1236

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

Similar topics

3
by: serge | last post by:
How do I determine which method I should use if I want to optimize the performance of a database. I took Northwind's database to run my example. My query is I want to retrieve the Employees'...
1
by: serge | last post by:
How do I determine which method I should use if I want to optimize the performance of a database. I took Northwind's database to run my example. My query is I want to retrieve the Employees'...
1
by: prileep | last post by:
I have two tables Users and UserLogin. Here i will use two methods of table design. and which query will return me the result more fast. The table size will be large that it may contain records in...
1
by: anuragvatsa | last post by:
please help me to write a query in which i have to genrate report on basis of given columns from different tables. am using sql server 2005 thx & regards
0
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,...
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
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,...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.