I have an example where I don't quite understand. What is the optimal way to solve it?
A table called usuarios
.
A table called publicaciones
.
If I plan to save the records of a post with that id
of the user who registered it; is the following structure correct?
But for example considering that an intermediate table called publicaciones-usuarios
with a structure similar to the following could be created:
What is the optimal way?, since for example if I make the first structure with a inner join
like the following:
SELECT titulo, cuerpo, username FROM publicaciones
INNER JOIN usuarios
ON usuarios.id = publicaciones.usuarios_id
WHERE usuarios.id = 2;
I can extract the publications that a user makes taking into account that the link between both tables is that id
of the user as a foreign key in the table publicaciones
; but I don't quite understand under what scenarios each one is used
It is just an example considering that I seek to clarify this doubt