473,398 Members | 2,120 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,398 software developers and data experts.

is it possible?

With the query below a participant can have more than one event to their
name. Is it possible to have the results somehow group the event names
to each participant or row? So, if the participant is registered for 3
events the row will have his/her name and the 3 event names, rather than
3 rows with their name and each event name.

Thanks.

SELECT participantID,fname,lname,eventname FROM
((((participant as p
LEFT OUTER JOIN regpartrel as rp ON p.participantID=rp.relparticipantID)
LEFT OUTER JOIN registration as r ON
rp.relregistrationID=r.registrationID)
LEFT OUTER JOIN subevent as se ON r.relsubeventID=se.subeventID)
LEFT OUTER JOIN event as e ON se.releventID=e.eventID)
WHERE fname LIKE '%brad%'
GROUP BY p.participantID
ORDER BY fname, lname, participantID

Jul 23 '05 #1
4 1366
Pasquale wrote:
With the query below a participant can have more than one event to their
name. Is it possible to have the results somehow group the event names
to each participant or row? So, if the participant is registered for 3
events the row will have his/her name and the 3 event names, rather than
3 rows with their name and each event name.


With temp-tables or subqueries, that should be possible (not sure how to
do that exactly). I personally do that in the application logic usually.
Jul 23 '05 #2
Pasquale wrote:
With the query below a participant can have more than one event to their
name. Is it possible to have the results somehow group the event names
to each participant or row? So, if the participant is registered for 3
events the row will have his/her name and the 3 event names, rather than
3 rows with their name and each event name.


If you use MySQL 4.1.6 or higher, MySQL has a grouping function
GROUP_CONCAT().

I haven't used it, but from the docs I believe the usage in your case
would be:

SELECT p.participantID, p.fname, p.lname,
GROUP_CONCAT(DISTINCT e.eventname SEPARATOR ', ') AS event_list
FROM ((((participant as p
LEFT OUTER JOIN regpartrel as rp
ON p.participantID=rp.relparticipantID)
LEFT OUTER JOIN registration as r
ON rp.relregistrationID=r.registrationID)
LEFT OUTER JOIN subevent as se
ON r.relsubeventID=se.subeventID)
LEFT OUTER JOIN event as e
ON se.releventID=e.eventID)
WHERE p.fname LIKE '%brad%'
GROUP BY p.participantID
ORDER BY p.fname, p.lname, p.participantID

See http://dev.mysql.com/doc/mysql/en/gr...functions.html.

Regards,
Bill K.
Jul 23 '05 #3


Bill Karwin wrote:
Pasquale wrote:
With the query below a participant can have more than one event to
their name. Is it possible to have the results somehow group the event
names to each participant or row? So, if the participant is registered
for 3 events the row will have his/her name and the 3 event names,
rather than 3 rows with their name and each event name.

If you use MySQL 4.1.6 or higher, MySQL has a grouping function
GROUP_CONCAT().


Is there an alternative to GROUP_CONCAT() for MySQL 4.0.23?
I haven't used it, but from the docs I believe the usage in your case
would be:

SELECT p.participantID, p.fname, p.lname,
GROUP_CONCAT(DISTINCT e.eventname SEPARATOR ', ') AS event_list
FROM ((((participant as p
LEFT OUTER JOIN regpartrel as rp
ON p.participantID=rp.relparticipantID)
LEFT OUTER JOIN registration as r
ON rp.relregistrationID=r.registrationID)
LEFT OUTER JOIN subevent as se
ON r.relsubeventID=se.subeventID)
LEFT OUTER JOIN event as e
ON se.releventID=e.eventID)
WHERE p.fname LIKE '%brad%'
GROUP BY p.participantID
ORDER BY p.fname, p.lname, p.participantID

See http://dev.mysql.com/doc/mysql/en/gr...functions.html.

Regards,
Bill K.


Jul 23 '05 #4
Pasquale wrote:
Is there an alternative to GROUP_CONCAT() for MySQL 4.0.23?


No, there is not. You either need to upgrade to MySQL 4.1, or else
retrieve your results as you are currently doing, and then manipulate
the result set in your application code.

Not everything can be done in SQL. Sometimes you just have to write
some code.

Regards,
Bill K.
Jul 23 '05 #5

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

Similar topics

4
by: Julia Briggs | last post by:
I am struggling to create a PHP function that would take a specified image (JPG, GIF or PNG) from a link, and resize it down to a thumbnail so it will always fit in a 200x250 space. I am hoping...
36
by: rbt | last post by:
Say I have a list that has 3 letters in it: I want to print all the possible 4 digit combinations of those 3 letters: 4^3 = 64 aaaa
20
by: CHIN | last post by:
Hi all.. here s my problem ( maybe some of you saw me on other groups, but i cant find the solution !! ) I have to upload a file to an external site, so, i made a .vbs file , that logins to...
7
by: Andrzej | last post by:
Is it possible to call a function which name is given by a string? Let assume that I created a program which call some functions for example void f1(void), void f2(void), void f3(void). ...
2
by: Bhupesh Naik | last post by:
This is a query regarding my problem to make a spell and grammar check possible in text area of a web page. We have aspx pages which are used to construct letters. The browser based screens...
1
by: AAA | last post by:
hi, I'll explain fastly the program that i'm doing.. the computer asks me to enter the cardinal of a set X ( called "dimX" type integer)where X is a table of one dimension and then to fill it...
25
by: Piotr Nowak | last post by:
Hi, Say i have a server process which listens for some changes in database. When a change occurs i want to refresh my page in browser by notyfinig it. I do not want to refresh my page i.e....
4
by: RSH | last post by:
Okay my math skills aren't waht they used to be... With that being said what Im trying to do is create a matrix that given x number of columns, and y number of possible values i want to generate...
7
by: Robert S. | last post by:
Searching some time now for documents on this but still did not find anything about it: Is it possible to replace the entry screen of MS Office Access 2007 - that one presenting that default...
14
by: bjorklund.emil | last post by:
Hello pythonistas. I'm a newbie to pretty much both programming and Python. I have a task that involves writing a test script for every possible combination of preference settings for a software...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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...
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,...

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.