I run into an inconvenience, I have a pots table, a comments table and a users table, I need to get in a single query the name of the user who owns the post, the name of the users who comment on the posts, it turns out that the mess I have is in a query get 2 different names from the same table twice, and the clause with which I search is the id of the post, I have this query and it brings me the data I need to get the name of those who comment, but the query gives me the id of the owner of that comment, the structure of the database is: users=id,name posts=id,title,description,user_id which is a foreign key of users.id comments=id,comment,id_post foreign key of post.id, id_user foreign key of users.id
The statement that I execute is the following:
select * from users inner join posts on posts.user_id= users.id inner join comentarios on comentarios.post_id=posts.id where posts.id=413
It brings me all the data well, it brings me the owner of the post and it brings me the fields of the comments table as well, only that it brings me the fields with id_user,_id_post and now I also need to obtain the name of that id_users that is generated in the table comments since he is the owner of the comment.
I don't know if I understand you properly, but if what you need is only the names of the users of the post and the comments, I understand that something like this should be:
That will return a row for each comment author, with the name of the post author and the comment author.
Something like that:
That means that the Post was written by Pablo, and has comments from Julián, Alberto and Ernesto.