mysql - Join and have child table go into new columns on the parent table -


i wondering if possible; able have 2 tables join them, have names (or field choose) on child table, go parent table, in new columns

so have table 1 'site'. designates sites of programs.
table 2 attendees, records people @ site @ day.

+--------+--------------------------+-------------+-------+-------+------------+ | p2p_id | address                  | city        | state | zip   | date       | +--------+--------------------------+-------------+-------+-------+------------+ |    44  | 435 s                    | los angeles | ca    | 90048 | 2014-05-13 | |    45  | 1641 whatever  ave       | santa ana   | ca    | 92704 | 2014-05-16 | |    46  | 1710 reterrr st          | denver      | co    | 80202 | 2014-07-10 | |    47  | 6401 fdgdfdffffave       | raleigh     | nc    | 27617 | 2014-07-16 | |    48  | east dfgdfgdf  street    | san antonio | tx    | 76107 | 2014-05-13 | |    126 | 3100 fgdfgffgf           | fort worth  | tx    | 76107 | 2014-05-14 | |    127 | 1001 dfgdfgdffff         | houston     | tx    | 77002 | 2014-05-20 | |    128 | 303 fdgdfgfgfgf          | atlanta     | ga    | 30308 | 2014-05-22 | |    129 | 2525 w end ave           | nashville   | tn    | 37203 | 2014-05-22 | |    13  | 2041 s xzcdfdf           | anaheim     | ca    | 92802 | 2014-05-28 | +--------+--------------------------+-------------+-------+-------+------------+ 

and have 'attend' table or table 2

+------------+-------------+--------+ | first_name | last_name   | p2p_id | +------------+-------------+--------+     |bara    | edgar       | 44     |        | estelle     | 44     |chi     | ng          | 44     |nhar    | poon        | 44     |ie      | byrd        | 48     |nie     | gilet       | 48     |nie     | hawley      | 48     |helle   | hewlett     | 48     |orah    | siler       | 48     |hy      | sommerville | 48 +------------+-------------+--------+ 

the p2p_id primary key on 'site' table , p2p_id foreign key on 'attend' table.

the question join

select * site s  join attend on s.p2p_id=a.p2p_id   +--------+--------------------------+-------------+-------+-------+------------+ ------------+-------------+--------+ | p2p_id | address                  | city        | state | zip   | date       |  first_name | last_name   | p2p_id | +--------+--------------------------+-------------+-------+-------+------------+ ------------+-------------+--------+ |    44  | 435 s                    | los angeles | ca    | 90048 | 2014-05-13 |     bara    | edgar       | 44 |    44  | 435 s                    | los angeles | ca    | 90048 | 2014-05-13 |             | estelle     | 44 |    44  | 435 s                    | los angeles | ca    | 90048 | 2014-05-13 |     chi     | ng          | 44  |    44  | 435 s                    | los angeles | ca    | 90048 | 2014-05-13 |     nhar    | poon        | 44 |    44  | 435 s                    | los angeles | ca    | 90048 | 2014-05-13 |      ie     | byrd        | 48 |    48  | east dfgdfgdf  street    | san antonio | tx    | 76107 | 2014-05-13 |     nie     | gilet       | 48 |    48  | east dfgdfgdf  street    | san antonio | tx    | 76107 | 2014-05-13 |     helle   | hewlett     | 48 |    48  | east dfgdfgdf  street    | san antonio | tx    | 76107 | 2014-05-13 |     orah    | siler       | 48 |    48  | east dfgdfgdf  street    | san antonio | tx    | 76107 | 2014-05-13 |     hy      | sommerville | 48 

but instead of multiple rows of same site popping up, possible sql (mysql) put in format?

+--------+--------------------------+-------------+-------+-------+------------+ ------------+-------------+ ------------+-------------+------------+-------------+ | p2p_id | address                  | city        | state | zip   | date       |  first_name | last_name   |  first_name | last_name   | first_name | last_name   | +--------+--------------------------+-------------+-------+-------+------------+ ------------+-------------+ ------------+-------------+------------+-------------+ |    44  | 435 s                    | los angeles | ca    | 90048 | 2014-05-13 |     barb    | edgar       |             | estelle     |    chi     | ngu         | |    48  | east dfgdfgdf  street    | san antonio | tx    | 76107 | 2014-05-13 |     helle   | hewlett     |     sarah   | siler       |    barbara | walters     | 

and if wondering why don't create new columns in parent table names...well don't want store data way, other people in company need me export data in format.

thanks!!

as far know isn't possible without crazy temporary tables. think best can process results programming after use group_concat function this:

select a.p2p_id, a.address,a.city, a.state,a.zip, a.date, group_concat(concat(first_name,' ', last_name)) name site s  join attend on s.p2p_id=a.p2p_id  group a.p2p_id, a.address,a.city, a.state,a.zip, a.date,  

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -