In my system, there is a system of postings and another system of friendships. Here is the structure of the tables:
posts : id | usuario | conteudo | data | hora
Friendships : id | usuario1 | usuario2 | status
And I'm using the following query to return the posts of both the current user and my friends (when status = 2
):
SELECT
postagem.id, usuario, conteudo, data, hora, usuario1, usuario2, status
FROM
postagens postagem
LEFT JOIN
amizades ON usuario = usuario1 OR usuario = usuario2
WHERE
status = 2 OR usuario = Igor
ORDER BY
postagem.id DESC
LIMIT 10
It's working perfectly, returning both my logged-in and my friends posts (relationship between users where status = 2
), and here's an example of data contained in the amizades
table:
2 | Igor | Joao | 2
1 | Lucas | Igor | 0
In the above data, when status = 2
means that they are friends, and when status = 0
means they are not friends.
But since there is my user (Igor) in the two rows of the table, it duplicates the posts of that user, that is, if there were another row in the table, which would make the friendship relationship between my user and another would triple the posts. How do I resolve this?