简体   繁体   English

在SQL中将记录合并到一个或多个

[英]Merge records or more into one in SQL

So I have this query: 所以我有这个查询:

SELECT * 
FROM `Nieuws`
INNER JOIN `Nieuws_tags` ON `Nieuws_tags`.`ID-Nieuws` = `Nieuws`.`ID` 
INNER JOIN `Tags` ON `Tags`.`ID` = `Nieuws_tags`.`ID-tags` 
WHERE Nieuws.ID = 1

Right now my output is: 现在我的输出是:

在此处输入图片说明

What I need: 我需要的:

在此处输入图片说明

So I need one record where the "Beschrijving" (tag) stack up and not give me 2 records. 因此,我需要一条记录,其中“ Beschrijving”(标签)堆积了,并且没有给我2条记录。

Someone told me about GROUP_CONCAT but I don't really know how to insert that if necessary. 有人告诉我有关GROUP_CONCAT的信息,但我真的不知道如何在必要时插入它。

It is not 100% clear what is your DB schema, but just to show you the usage of GROUP_CONCAT function: 还不是100%清楚您的数据库模式是什么,而只是向您展示GROUP_CONCAT函数的用法:

SELECT Nieuws.*,
       GROUP_CONCAT(Tags.Beschrijving)
FROM `Nieuws`
INNER JOIN `Nieuws_tags` 
ON `Nieuws_tags`.`ID-Nieuws` = `Nieuws`.`ID` 
INNER JOIN `Tags` 
ON `Tags`.`ID` = `Nieuws_tags`.`ID-tags` 
WHERE Nieuws.ID = 1
GROUP BY Nieuws.ID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM