I solved my problem, my teacher reminded me that as I was picking up *, the records returned were different because of the_tagcolumn, so the distinct would not work, to solve it was just not to take the_tagcolumn. As for what I needed just needed the post.id_post, it only returns single id records.
SELECT DISTINCT postagem.id_postagem FROM postagem
INNER JOIN tag_post on postagem.id_postagem = tag_post.id_postagem
INNER JOIN tag ON tag.id_tag = tag_post.id_tag
WHERE tag.nome_tag LIKE '%quimica%';
and without the DISTINCT
SELECT postagem.id_postagem FROM postagem
INNER JOIN tag_post on postagem.id_postagem = tag_post.id_postagem
INNER JOIN tag ON tag.id_tag = tag_post.id_tag
WHERE tag.nome_tag LIKE '%quimica%';
But there are two records with the same
id_postagem
withnome_tag
different. They are two different things. If you only want one, which one?– Sam
It’s a bit confusing your question. What is the result you would like to get? Because with Inner Join you get the related data of the two tables. In this case, as I understand it, you’re taking all the posts' tags.
– Rafa C.
In what you posted there are no fully duplicated lines. Explain better what kind of "duplicity" you want to avoid.
– anonimo
You’d have to send examples of the tables as well, not just the view. And a tip: usually those who use DISTINCT are already doing something wrong, DISTINCT is a band-aid and almost always have a better way.
– epx