MySQL-PHP Multiple members and join names to dates -


i have table of 'members' looks following. in trying put mailing list found addresses easy. names on other hand, not much.

| id | firstname | lastname | mbrgrpnum | mbrgrpnumid | datejoined | -------------------------------------------------------------------- | 1  | jane      | whitmore | 100100    | 01          | 2016-01-01 | | 2  | bob       | whitmore | 100100    | 02          | 2014-02-01 | | 3  | carol     | evans    | 100101    | 01          | 2012-02-01 | | 4  | bob       | roahns   | 100101    | 02          | 2015-09-28 | | 5  | corry     | roahns   | 100101    | 03          | 2014-09-28 | 

the output i'd this, based on mbrgrpnum;

1 whitmore, jane (01/16) & bob (02/14) 2 evans, carol (02/12) & rohns, bob (09/15) & corry (09/14) 

there 6 individuals same mbrgrpnum (essentially members of household) different mbrgrpnumid's.

use concat concatenate columns in row, , group_concat concatenate in group.

select group_concat(         concat(lastname, ', ', firstname, ' (',                 date_format(datejoined, '%m/%y'), ')')         separator ' & ') members members group mbrgrpnum 

to combine members same last name, need use subquery find them.

select group_concat(concat(lastname, ', ', family_members) separator ' & ') members (     select mbrgrpnum, lastname,             group_concat(                 concat(firstname, ' (', date_format(datejoined, '%m/%y'), ')') separator ' & ') family_members     members     group mbrgrpnum, lastname) families group mbrgrpnum 

demo


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -