1
I have the tables below:
- Articles
- tags
- article_tag (pivot table with the columns article_id and tag_id)
In the query below I can recover the articles that have the two tags (with id 1 and 3). In the query only articles that have the two tags that will have their ids shown.
select article_id
from article_tag
where tag_id in (1, 3)
group by article_id
having count(distinct tag_id) = 2;
How to make a select Count for me to know the total of records returned without displaying the data itself?
Is that in the query above I have the listing for example:
| article_id |
--------------
| 289 |
| 341 |
But I wanted something like (total of articles that have the two tags):
| total_articles |
------------------
| 2 |
article_id is PK?
– Ricardo
Yes, PK in table Articles and FK in table article_tag
– rodrigoum