P
P
Paka2020-02-29 10:54:22
MySQL
Paka, 2020-02-29 10:54:22

How to choose tags that are strictly registered for all articles in a given topic?

There is a table

`news_tag` (
    `theme_id` INT
    `news_id` INT
    `tag_id` INT
)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2020-02-29
@Paka

SELECT DISTINCT tag_id FROM news_tag WHERE theme_id = КодСтрогоЗаданнойТемы

because it is in both articles

SELECT tag_id
  FROM news_tag
  WHERE (theme_id = 1)
  GROUP BY tag_id
  HAVING COUNT(news_id) = ( SELECT COUNT(DISTINCT(news_id)) FROM news_tag WHERE (theme_id = 1) )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question