[英]Return one row for a table Left join with another table has multirow with same ID
customers table: 客户表:
notes table: 备注表:
MY SQL query didn't work 我的SQL查询无效
SELECT * FROM customers LEFT JOIN notes ON customers.customer_id = notes.customer_id GROUP BY notes.customer_id
I want to return one row for customer_id 277 : Mr,Kevin, New notes, Service, 2017-06-17 12:37:28 New note 2, Lead, 2017-06-17 15:04:42 我想为customer_id 277返回一行:Mr,Kevin,新记录,服务,2017-06-17 12:37:28新记录2,线索,2017-06-17 15:04:42
customers table left join with multi tables 客户表左连接多表
You could use a group_concat on formatted result for notes 您可以在格式化结果上使用group_concat作为注释
select a.customer_id, a.ttle, a.first_name, group_concat(t.note_row)
from customer
inner join (
select customer_id, concat(note, ' ', note_type, ' ', note_date_added ) as note_row
from notes
) t on t.customer_id = a.customer_id
group by a.customer_id, a.ttle, a.first_name
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.