Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 在SQL中将一个或多个记录合并为一个_Mysql_Sql_Database - Fatal编程技术网

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

Mysql 在SQL中将一个或多个记录合并为一个,mysql,sql,database,Mysql,Sql,Database,所以我有一个疑问: 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 现在我的输出是: 我需要的是: 因此,我需要一条记录,其中Beschrijving标记堆叠起来,而不是给我2条记录 有人告诉我有

所以我有一个疑问:

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
现在我的输出是:

我需要的是:

因此,我需要一条记录,其中Beschrijving标记堆叠起来,而不是给我2条记录


有人告诉我有关GROUP_CONCAT的事,但我真的不知道如何在必要时插入它。

您的DB模式不是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

MySQL或SQL标记please and combined通常都是好的。@jarlh不是这样的,这是我在这里学到的一个艰难的教训:-我想这在这里得到了回答,这也有点取决于DBMS-有些需要处理特定的命令this@ErikReder,这是SQL Server的答案,它不适用于MySQL。