I have the posts table with the following data /structure:
posts_id post_message u_id like_count created
===================================================
1 content....... 1 25 1559041633
2 content....... 2 25 1559041633
and posts_like table with the following data/structure:
like_id posts_id u_id r_id created
=============================================
22 2 1 2 1559041633
27 2 2 4 1559041633
30 1 2 7 1559041633
Note: u_id means the user id, r_id means reaction id, posts_id means posts id.
Now, I want to get all posts from the posts table along with the full name from the users table and all u_id and r_id under each post.
For example, you can see that under posts_id = 2 I have u_id 1 and 2 and r_id 2 and 4.
Desire Output:
first post content
user full Name
u_id: 2
r_id: 7
second post content
user full Name
u_id: 1, 2
r_id: 2, 4
Current I am using this SQL query
$query = $this->_db->_pdo->prepare("
SELECT p.posts_id, p.post_message, p.like_count, p.created, u.full_name,
u.u_id, pl.r_id FROM posts AS p LEFT JOIN users AS u ON u.u_id = p.u_id
LEFT JOIN posts_like AS pl ON pl.posts_id = p.posts_id GROUP BY
p.posts_id ORDER BY p.posts_id DESC ");
This above query does not get the all u_id and r_id under each post.