I ended up figuring this out. If anyone ever needs it, this works well

select module_id, GROUP_CONCAT(participant_answer SEPARATOR ' ') as answers 
from participants_answers 
where email = '[EMAIL PROTECTED]' 
group by module_id

-Brian


-----Original Message-----
From: Brian Menke [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, March 07, 2007 6:23 PM
To: 'MySQL List'
Subject: How do I alter the result of a select

MySQL 5.x

I have a table that looks like this:

module_id question_id email                     participant_answer 
2         2.1         [EMAIL PROTECTED]         a                  
2         2.2         [EMAIL PROTECTED]         b                  
2         2.3         [EMAIL PROTECTED]         c                  
2         2.4         [EMAIL PROTECTED]         d                  
2         2.5         [EMAIL PROTECTED]         e                  
1         1.1         [EMAIL PROTECTED]         a                  
1         1.2         [EMAIL PROTECTED]         c                  
1         1.3         [EMAIL PROTECTED]         d                  
1         1.4         [EMAIL PROTECTED]         b                  
1         1.5         [EMAIL PROTECTED]         d                  
5         5.1         [EMAIL PROTECTED]         a                  
5         5.2         [EMAIL PROTECTED]         c                  
5         5.3         [EMAIL PROTECTED]         d                  
5         5.4         [EMAIL PROTECTED]         b                  
5         5.5         [EMAIL PROTECTED]         d

Being an SQL novice, whenever I run any kind of selects, for example 

select * 
from table_name
where email = '[EMAIL PROTECTED]' 

I get the results in rows just like you would see above, which is what I
would expect. What I really need is this format

Module ID       Participants Answers

1               a b c d e
2               a b c d e
5               a c d b d

Instead of 1 row for each listed module id. I tried grouping by module_id
such as

select * 
from table_name
where email = '[EMAIL PROTECTED]'
group by module_id

But that ended up just giving me 1 row with one answer. I think the solution
is grouping somehow, but I'm not quite experienced enough to put it all
together.

Any help is greatly appreciated, even if it's just a pointer to some mysql
docs.

Thanks in advance!

-Brian Menke                 


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to