mysql - Group by Where(field.id is the same) -
table header
x---id---x---short_name---------x | 1 | alcatel | | 2 | nexus | | 3 | zte | x--------x----------------------x
table detail
x---id---x---------code---------x---header.id---x | 1 | xxx | 1 | | 2 | zzz | 2 | | 3 | zzz | 2 | | 4 | xxx | 3 | x--------x----------------------x---------------x
and need group code field.id same, example: in case 2 rows same field.id need group field code in case if field.id same.. (very hard me explain...)
i need
x---header.id---x--detail.id--x-----short_name----x---detail.code---x | 1 | 1 | alcatel | xxx | | 2 | 3 | nexus | zzz | | 3 | 4 | zte | xxx | x---------------x-------------x------------------x-----------------x
i don't know if possible do, if please me, if isn't please tell me impossible.
edit: field.id , field.code (the id , code fields) table relashion 1 n called field
select h.id header_id, max(d.id) detail_id, h.short_name, d.code header h join detail d on d.`header.id` = h.id group header_id, h.short_name, d.code
Comments
Post a Comment