Php 如何在一对多关系中连接表时避免重复键?

Php 如何在一对多关系中连接表时避免重复键?,php,mysql,join,Php,Mysql,Join,我试图查询6个表,但在查询结果中得到了重复的主键。以下是表格: 用户文章 id nomarticles 1 escarpin_estelle 2 Tallon_grace idsizes size 1 36 2 38 3 40 4 44 5 32 id_article id_matiere 1 2 1 1 2 3 2 3

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

用户文章

id nomarticles 
 1 escarpin_estelle
 2 Tallon_grace
idsizes size
  1       36
  2       38
  3       40
  4       44
  5       32
id_article id_matiere
  1          2
  1          1
  2          3
  2          3
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
文章大小

productid  idsizes
 1          1
 1          2
 2          3
 2          5
matiereid  matierename
 1          daim
 2          coton
 3          polyster
id  articlename        size   filenames                            matiere 
 1  escarpin_estelle   38,45  rouge2017-10-03.jpg,moulante201.jpg  coton,daim
尺寸

id nomarticles 
 1 escarpin_estelle
 2 Tallon_grace
idsizes size
  1       36
  2       38
  3       40
  4       44
  5       32
id_article id_matiere
  1          2
  1          1
  2          3
  2          3
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
articlematieres

id nomarticles 
 1 escarpin_estelle
 2 Tallon_grace
idsizes size
  1       36
  2       38
  3       40
  4       44
  5       32
id_article id_matiere
  1          2
  1          1
  2          3
  2          3
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
matiere

productid  idsizes
 1          1
 1          2
 2          3
 2          5
matiereid  matierename
 1          daim
 2          coton
 3          polyster
id  articlename        size   filenames                            matiere 
 1  escarpin_estelle   38,45  rouge2017-10-03.jpg,moulante201.jpg  coton,daim
文章\u imgs

id nomarticles 
 1 escarpin_estelle
 2 Tallon_grace
idsizes size
  1       36
  2       38
  3       40
  4       44
  5       32
id_article id_matiere
  1          2
  1          1
  2          3
  2          3
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
期望的结果应该是

productid  idsizes
 1          1
 1          2
 2          3
 2          5
matiereid  matierename
 1          daim
 2          coton
 3          polyster
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个材质

除非在
WHERE

**---可选--**


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

您确实有多个答案:

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

除非在
WHERE

**---可选--**


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

您使用的是哪种RDBMS?SQL Server还是MySQL?@pcdev我正在使用MySQL,看看它是否有用。我想您正在寻找
GROUP\u CONCAT()
函数,但我对MySQL没有经验,很抱歉。根据desire的输出,没有样本数据。能否更正您的示例数据和预期输出?您使用的是哪种RDBMS?SQL Server还是MySQL?@pcdev我正在使用MySQL,看看它是否有用。我想您正在寻找
GROUP\u CONCAT()
函数,但我对MySQL没有经验,很抱歉。根据desire的输出,没有样本数据。能否更正您的示例数据和预期输出?