Re: Joining result sets into 1 row

2006-08-14 Thread Brent Baisley

I think what you are looking for is GROUP_CONCAT. Without more info I can't 
really tell though.
http://dev.mysql.com/doc/refman/4.1/en/group-by-functions.html

- Original Message - 
From: Steffan A. Cline [EMAIL PROTECTED]

To: mysql@lists.mysql.com
Sent: Sunday, August 13, 2006 6:53 PM
Subject: Joining result sets into 1 row



I am in a situation where I have say 1 column called attribute I need and
the result set is 3 rows. i.e.
ROW 1 - Mechanic
ROW 2 - Carpenter
ROW 3 - Plumber
I want to have the rows returned as one row
Such as 
ROW 1 Mechanic, Carpenter, Plumber


Something like a literal join would be beautiful such as :
ROW 1 Mechanic, Carpenter and Plumber

I think the latter is asking for too much but the first would be awesome.

Any advice is much appreciated!


Thanks

Steffan

---
T E L  6 0 2 . 5 7 9 . 4 2 3 0 | F A X  6 0 2 . 9 7 1 . 1 6 9 4
Steffan A. Cline
[EMAIL PROTECTED] Phoenix, Az
http://www.ExecuChoice.net  USA
AIM : SteffanC  ICQ : 57234309
 Lasso Partner Alliance Member
---




--
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]



Re: Joining result sets into 1 row

2006-08-14 Thread Brad Jahnke
 I want to have the rows returned as one row
 Such as 
 ROW 1 Mechanic, Carpenter, Plumber

You may want to try GROUP_CONCAT(expr)  ...

http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html


 


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



Re: Joining result sets into 1 row

2006-08-14 Thread Ow Mun Heng
On Mon, 2006-08-14 at 05:43 -0700, Steffan A. Cline wrote:
 Here is a better example
 
 mysql select listName from listItem limit 3;
 +-+
 | listName|
 +-+
 | PWC |
 | Small Boats |
 | Fiberglass  |
 +-+
 3 rows in set (0.02 sec)
 
 mysql 
 
 
 Rather than return 3 rows I would like the data retruned as
 
 mysql select listName from listItem limit 3;
 +--+
 | listName |
 +--+
 | PWC, Small Boats, Fiberglass |
 +--+
 1 row in set (0.02 sec)

Seems like what you want is to concat everything into 1 line separated
by Commas?
Hmm.. Not very sure how to get that done.

Is there anything which is unique about each item in the list?

Please Send to the Maillist as you will get more response from more
knowledgeable people there.


  Not sure how your row are. is it really marked as Row1/Row2/Row3?
  If yes, you can use a case expression.
  
  select
  case when row=row1 then row else null end as mechanic ,
  case when row=row2 then row  else null end as carpenter,
  end



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



Joining result sets into 1 row

2006-08-13 Thread Steffan A. Cline
I am in a situation where I have say 1 column called attribute I need and
the result set is 3 rows. i.e.
ROW 1 - Mechanic
ROW 2 - Carpenter
ROW 3 - Plumber
I want to have the rows returned as one row
Such as 
ROW 1 Mechanic, Carpenter, Plumber

Something like a literal join would be beautiful such as :
ROW 1 Mechanic, Carpenter and Plumber

I think the latter is asking for too much but the first would be awesome.

Any advice is much appreciated!


Thanks

Steffan

---
T E L  6 0 2 . 5 7 9 . 4 2 3 0 | F A X  6 0 2 . 9 7 1 . 1 6 9 4
Steffan A. Cline
[EMAIL PROTECTED] Phoenix, Az
http://www.ExecuChoice.net  USA
AIM : SteffanC  ICQ : 57234309
  Lasso Partner Alliance Member
---




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



Re: Joining result sets into 1 row

2006-08-13 Thread Ow Mun Heng
On Sun, 2006-08-13 at 15:53 -0700, Steffan A. Cline wrote:
 I am in a situation where I have say 1 column called attribute I need and
 the result set is 3 rows. i.e.
 ROW 1 - Mechanic
 ROW 2 - Carpenter
 ROW 3 - Plumber
 I want to have the rows returned as one row
 Such as 
 ROW 1 Mechanic, Carpenter, Plumber
 
 Something like a literal join would be beautiful such as :
 ROW 1 Mechanic, Carpenter and Plumber

Not sure how your row are. is it really marked as Row1/Row2/Row3?
If yes, you can use a case expression.

select
case when row=row1 then row else null end as mechanic ,
case when row=row2 then row  else null end as carpenter,
end




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