Count how many records belong to 2 categories in a n to n relation
When you join topics to topics_to_articles to articles, each article may be tied to multiple topics. And, multiple topics may be associated with each collection. So, you may be counting the same article multiple times.

For example:


Collection A is tied to topics a,b,c
Collection B is tied to topics b,d,e
Article 1 is tied to topics a,b,e
Article 2 is tied to topics a,c
Article 3 is tied to topics b, d, e


If cat_1_id is 1 and cat_2_id is 2:


the IN clause will contain article IDs 1 and 3 (while the query will list them more than once, the IN clause doesn't care how many times an ID is listed, just whether it's there or not)
The main query will count:


article 1, topic a
article 1, topic b
article 1, topic c
article 3, topic b



If cat_1_id is 2 and cat_2_id is 1:


the IN clause will contain article IDs 1, 2, and 3
The main query will count:


article 1, topic b
article 1, topic e
article 3, topic b
article 3, topic d
article 3, topic e



The first query gives you 4; the second query gives you 5; you should really get 2 (because there are two distinct articles returned).

And, that word is the solution - DISTINCT

Change your two lines to:

SELECT
  COUNT(DISTINCT A.article_id) AS total


This way, when the same article_id shows up multiple times, it will still only be counted once.