Reputation: 55
How in MySQL, I want to get the results from the post table. I do this perfectly. However I would like to get the individual Likes from the like table and the comments from the Comments table.
How could I do this using the JOIN function? Each of the tables have the postID in common (id for the table Posts).
Upvotes: 1
Views: 73
Reputation: 29498
Don't use a join, get the posts, then for each post, get the likes & comments separately.
Psuedocode:
$posts['likes'] = $likes
.echo json_encode($posts)
Upvotes: 4
Reputation: 3989
SELECT * FROM `posts`
INNER JOIN `comments` ON `comments`.`postId` = `posts`.`postId`
INNER JOIN `likes` ON `likes`.`postId` = `posts`.`postId`
WHERE `posts`.`postId` = ?
Upvotes: 2