I'm currently using the following query
to select all saved posts in the database: "SELECT * FROM postagens ORDER BY id DESC LIMIT 7"
, however, I want to select only the posts made by "friends".
The relationship of friends is in the amizades
table, in which when they are friends, the status = 2
column. How do you relate both tables to select all posts made by "friends"?
What I've achieved so far:
SELECT
postagem.id, postagem.usuario, postagem.conteudo, postagem.data, postagem.hora,
amizade.usuario1, amizade.usuario2, amizade.status
FROM
postagens postagem
LEFT JOIN
amizades amizade ON postagem.usuario = amizade.usuario2
WHERE
amizade.status = 2
ORDER BY
postagem.id DESC
LIMIT 10
However, I want to select all the posts made by me and my friends (when amizade.status = 2
), and then I'm failing, I do not know how to select only my posts and my friends' appear.
Columns:
posts :
id | usuario | conteudo | data | hora
Friendships :
id | usuario1 | usuario2 | status