473,396 Members | 1,734 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,396 software developers and data experts.

Getting row data and a count - maybe simple

Help,

I have a query in MySQL which gets the details of members of a club.

e.g. Select * from members.

however, in the same query I want to return the amount of "functions"
the member has attended.

therefore there is a "functions" table and because functions has a
many-many relationship with members I also have a "functionslink"
table.

To get the amount of functions that a particular member has attended
one would write a query like so:

select count(functionlink_id) as cnt from functionslink where
functionlink.member_id=$MEMBER*_ID

What I want to do is just have the one query that not only returns all
the member data in its returned row, but also the count of the number
of functions they attended.
At present using PHP code, I make the two calls separately to construct
this data in to a php array, but this involves many more calls to the
DB because for each row returned by the first query, I make another
call to the DB and something tells me this is a slow bad way of doing
things.

I am sure this is a simple common query but I cannot work it out.

Thanks in advance.

Jul 23 '05 #1
2 1586
Gr*************@lycos.co.uk wrote:
Help,

I have a query in MySQL which gets the details of members of a club.

e.g. Select * from members.

however, in the same query I want to return the amount of "functions"
the member has attended.

therefore there is a "functions" table and because functions has a
many-many relationship with members I also have a "functionslink"
table.

To get the amount of functions that a particular member has attended
one would write a query like so:

select count(functionlink_id) as cnt from functionslink where
functionlink.member_id=$MEMBER*_ID

What I want to do is just have the one query that not only returns all
the member data in its returned row, but also the count of the number
of functions they attended.
At present using PHP code, I make the two calls separately to construct
this data in to a php array, but this involves many more calls to the
DB because for each row returned by the first query, I make another
call to the DB and something tells me this is a slow bad way of doing
things.

I am sure this is a simple common query but I cannot work it out.

Thanks in advance.


The following should work for you:

mysql> select m.membername, count(t.taskid)
-> from gOMembers m, gOTasks t
-> WHERE m.membername = t.membername
-> group by m.membername;

HTH
Jerry

Jul 23 '05 #2
Thanks for that, it did help using the group by query in one case.
However, in another case the table linking is so complex (it seems
anyway) that I do not think it is possible to apply the above.
Therefore I have to have a second SQL call for each row returned from a
first SQL call to get a count of something.

Is this quite a common scenario and there may be cases where the first
result will return 500 rows and then for each of these returned rows
another SQL call is made to get a count to assoicate with each row.
By displaying this count in my results page I am adding a further 500
calls to the DB (within the same function mind you so only one
connection). Is this very bad?

For those interested the query is like this
Display information on users, but also display the number of events
that the user has registered for (but only count them if the event is
open).

It is the counting if the event is open part I found hard to achieve in
one SQL statement.

Thanks

Jul 23 '05 #3

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

Similar topics

17
by: John Hunter | last post by:
I have a largish data set (1000 observations x 100 floating point variables), and some of the of the data are missing. I want to try a variety of clustering, neural network, etc, algorithms on the...
303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
17
by: Olivier Bellemare | last post by:
I've tried to make a function that returns the middle of a string. For example: strmid("this is a text",6,4); would return "is a". Here is my code: char *strmid(char *texte, int depart,...
6
by: Ken Varn | last post by:
I have an ASP.NET application that is calling a custom class that is trying to parse all of the members of my Page object using Type.GetMembers(). The problem that I am having is that private...
18
by: robert | last post by:
Is there a ready made function in numpy/scipy to compute the correlation y=mx+o of an X and Y fast: m, m-err, o, o-err, r-coef,r-coef-err ? Or a formula to to compute the 3 error ranges? ...
1
by: maiami2 | last post by:
Hi Guys, I'm very new to access and I've been trying to get the hang of it over the last few days, but I've become very confused with various aspects of how to code it. Introduction: I am...
3
by: TC | last post by:
Hey All, I have some classes that I recently built for a website which uses the HttpWebRequest & HttpWebResponse objects from the System.Net namespace. Basically, the classes rap submitted data...
1
by: sparks | last post by:
I have always just got a count on records and put up a box at the top of the entry forms saying something like 1 of 500 and updating it as you got to 500 of 500. I have never thought of this as...
23
by: tkpmep | last post by:
I have a list that starts with zeros, has sporadic data, and then has good data. I define the point at which the data turns good to be the first index with a non-zero entry that is followed by at...
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:
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
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
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
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...

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.