我使用select distinct是为了只返回不同的数据,但我希望它基于所有列的区别,而不在区别中包含agg_source_tag_tag_name。
我的问题是:

SELECT DISTINCT agg_article_title,agg_article_link,agg_article_media,agg_article_description,agg_article_source_name, agg_source_tag_tag_name, agg_source_url
FROM agg_article join agg_source ON agg_article_source_name = agg_source_name join agg_source_tag ON agg_source_name = agg_source_tag_source_name
WHERE agg_source_included = 1

我得到以下结果:
agg_article_title | agg_article_link | agg_article_media | agg_article_description | agg_article_source_name | agg_source_tag_tag_name | agg_source_url |
---------------------------------------------------------------------------------------------------------------------------------------------------------
some title 1      | some link 1      | some media 1      | some description 1      | some source name 1      | tag1                    | someurl1       |
---------------------------------------------------------------------------------------------------------------------------------------------------------
some title 1      | some link 1      | some media 1      | some description 1      | some source name 1      | tag2                    | someurl1       |

由于agg_source_tag_tag_name,所有列实际上都是不同的,因此返回以下内容,但是,我只想返回一行,因为我想从区别中省略agg_source_tag_tag_name。

最佳答案

用GROUP BY试试这个

  SELECT agg_article_title,agg_article_link,agg_article_media,agg_article_description,agg_article_source_name, agg_source_tag_tag_name, agg_source_url
  FROM agg_article
  join agg_source
  ON agg_article_source_name = agg_source_name
  join agg_source_tag
  ON agg_source_name = agg_source_tag_source_name
  WHERE agg_source_included = 1
  GROUP BY agg_article_title, agg_article_link

你可以按你想要的颜色分组。

关于mysql - 从1以外的所有列中选择唯一数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21832170/

10-14 05:33