Being as basic as possible.
Requirements
See for your own requirement:
- You have 1 post (which consequently has a primary key, I will call id_post). Which briefly has the attributes id, text of the post.
- You will get N comments on a post. The post will contain id_comment, id_post (Foreign key for Post) and comment.
Therefore, an association of 1 x N (A post has N comments, where N can be any number).
SQL
To identify the post:
SELECT * FROM postagem WHERE id_postagem = :numeroPostagem
To identify comments from that post:
SELECT * FROM comentario WHERE id_postagem = :numeroPostagem
Frequently asked questions
If I already have the id_post, why create an id for comment (id_comment) in the comment table ?
To be able to identify a comment from the other.
Why I have to take the post id (id_post) to the comment table ?
In order to identify which post that comment belongs to
I think I get the logic... Well, tomorrow I put in place and then put the results, I will certainly put as the best answer, but that was already a great help to open my mind. Thank you very much!
– Igor