mysql - mysql和php中fetech如何数据一对多关系
问题描述
我有一个表客户和第二个表订单。我已经从客户那里获取了,但它获取了重复的记录。
select customers.name, customers.mobile, orders.Product
from customers,
orders
where customers.id = orders.customer_id
结果 :
目标 :
解决方案
你需要在GROUP BY
你Customers
的Order
专栏
select c.name,
c.mobile,
group_concat(o.Product) #products name separated by a comma
from customers c
left join orders o on
c.id = o.customer_id
group by c.id
我不熟悉你的结构,但我想这就是你想要了解的要点
推荐阅读
- dhcp - 在获得 APIPA/LINK-LOCAL ADDR 后,是否可以停止 DHCP 客户端发送“发现”消息?
- ios - 您如何允许“文件”应用访问 Expo 应用中的内容?
- javascript - 我如何定义不和谐。“未定义错误不和谐”
- mysql - INSERT [LOW_PRIORITY | ] 的实际应用 延迟 | HIGH_PRIORITY] [忽略]
- android - Google 登录停止了 Play 商店构建工作
- mysql - Laravel 8:处理Mysql PDO连接超时的正确方法是什么
- python - 合并两个具有特定条件的列表
- python - Numpy errr - 对象对于所需数组来说太深
- django - 如何使用 Django 为现有表创建一对一字段?
- node.js - 为什么我不能在 linux 中更新 npm?