gpt4 book ai didi

php - 如何避免在一对多关系中连接表时出现重复键?

转载 作者:行者123 更新时间:2023-11-30 21:52:40 24 4
gpt4 key购买 nike

我尝试查询 6 个表,但在查询结果中得到了重复的主键。这是表格:

用户文章

id nomarticles 
1 escarpin_estelle
2 Tallon_grace

文章大小

productid  idsizes
1 1
1 2
2 3
2 5

尺寸

idsizes size
1 36
2 38
3 40
4 44
5 32

文章 Material

id_article id_matiere
1 2
1 1
2 3
2 3

Material

matiereid  matierename
1 daim
2 coton
3 polyster

article_imgs

imageid articleID filenames
1 1 rouge2017-10-03.jpg
2 1 2017-10-03-204220.jpg
3 2 moulante201.jpg
4 2 avec-decollete.jpg

愿望的结果应该是有

id  articlename        size   filenames                            matiere 
1 escarpin_estelle 38,45 rouge2017-10-03.jpg,moulante201.jpg coton,daim

这是我的查询:

SELECT id,nomarticle,filenames,size,matierename FROM userarticles AS products LEFT JOIN article_imgs AS images ON images.articleID = products.id LEFT JOIN articlesize AS prodt ON prodt.idarticle = products.id LEFT JOIN sizes AS s ON s.idsizes = prodt.idsize LEFT JOIN articlematieres AS prodmat ON prodmat.id_article = products.id LEFT JOIN matiere AS m ON m.matiereid = prodmat.id_matiere WHERE products.id = 1

最佳答案

真的确实有多个答案:

products.id = 1 有 2 个图像、2 个尺寸和 2 个 Material

除非您在 WHERE

中指定更多字段,否则您真的无法获得唯一的答案

** --- 可选 --- **

您可以将 LIMIT 1 添加到您的查询中以获得第一个,但这可能是错误的。

关于php - 如何避免在一对多关系中连接表时出现重复键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46555222/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com