使用多表 SQL 语句选择数据返回意外结果
我想格式化 SQL 结果,然后导出到 CSV(phpMyAdmin 导出)。
SQL语句:
SELECT
product.name,
features.text
FROM products as product, product_features as features
WHERE
features.product_id=products.id LIMIT 0,100
表结构:
表products
:
------------
id | name
------------
24 Baseball
25 Rope
表product_features
:
--------------------------
id | text | product_id
--------------------------
45 Leather.. 24
46 Hardball 24
47 Nylon 25
48 Black 25
问题:我得到:
Baseball Leather
Baseball Hardball
Rope Nylon
Rope Black
我很难理解什么使用 SQL 语句执行的解决方案类型。
我正在寻找的结果:
Baseball, Leather..., Hardball
Basketball, Nylon, Black
I want to format SQL results, then export to CSV (phpMyAdmin export).
SQL statement:
SELECT
product.name,
features.text
FROM products as product, product_features as features
WHERE
features.product_id=products.id LIMIT 0,100
Tables strucutre:
Table products
:
------------
id | name
------------
24 Baseball
25 Rope
Table product_features
:
--------------------------
id | text | product_id
--------------------------
45 Leather.. 24
46 Hardball 24
47 Nylon 25
48 Black 25
Problem: I get:
Baseball Leather
Baseball Hardball
Rope Nylon
Rope Black
I'm having a hard time wrapping my head around what type of solution do with a SQL statement.
Result I'm Looking for:
Baseball, Leather..., Hardball
Basketball, Nylon, Black
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将需要某种类型的聚合:
You'll need some type of aggregate: