我有2张这样的表:
出版物
publications id | publications field id | publications description
1000 | 1 | John
1000 | 2 | 2014
1000 | 4 | aa@...
1000 | 6 | 123-456-789
id = 1000表示一本书及其详细说明(作者姓名,年份,电子邮件,电话)
注册表
publications field id | component
1 | author name
2 | year
3 | date
4 | e-mail
5 | price
6 | tel
注册表意味着一本书的格式表
我想要合并2个这样的表:
publications id | publications description
1000 | John,2014,NULL,aa@..,NULL,123-456-789
NULL表示此book(id=1000)
的字段ID 3
和5
为NULL
所以,我使用左连接:
SELECT registry.publications field id,component,publications id, publications description
FROM registry
LEFT JOIN publications
on publications.publications field id = registry.publications field id
但结果是:
publications field id | component | publications id | publications description
1 | author name | 1000 | John
2 | year | 1000 | 2014
3 | date | NULL | NULL
4 | e-mail | 1000 | aa@..
5 | price | NULL | NULL
6 | tel | 1000 | 123-456-789
我知道下一步是使用group_concat(IFNULL(publications description,'NULL'))
但如何按publications id
分组?当某些publications id
为NULL时?