我正在使用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。
答案 0 :(得分:1)
尝试使用WITH 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
你可以根据自己想要的东西进行分组。