Garayed.com  

Go Back   Garayed.com > mySQL
FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-03-2008, 09:15 PM
Leon Williams
 
Posts: n/a
Default Getting a join result as a list.

I have two tables a and b with a many to one relationship.
I know its possible to do a join and get as may records back as my
many relationship has.

But, is it possible to get only one field back as a list.

The result would look like this:

select id. name, magic_list( table_b_types )
from table_a
join table_b on table_a.id = table_b.a_id


id, name, table_b_types
1, "Normal Bees", " worker drone "

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-04-2008, 02:39 PM
Leon Williams
 
Posts: n/a
Default Re: Getting a join result as a list.

On Apr 3, 5:15 pm, Leon Williams <noel.ja...@gmail.com> wrote:
> I have two tables a and b with a many to one relationship.
> I know its possible to do a join and get as may records back as my
> many relationship has.
>
> But, is it possible to get only one field back as a list.
>
> The result would look like this:
>
> select id. name, magic_list( table_b_types )
> from table_a
> join table_b on table_a.id = table_b.a_id
>
> id, name, table_b_types
> 1, "Normal Bees", " worker drone "


FYI,

The magic_list function in the example above is GROUP_CONCAT.

So the above sudo query would be something like this

select id. name, GROUP_CONCAT( ( select table_b_types from table_b
where table_a.id = table_b.a_id ) )
from table_a
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 03:29 AM.




LinkBacks Enabled by vBSEO 3.0.0 © 2007, Crawlability, Inc.