A
A
Alexander Tishchenko2021-07-06 21:25:28
MySQL
Alexander Tishchenko, 2021-07-06 21:25:28

Why is data duplicated after fetching from MySQL database when using 3 JOINs?

Hello.
There are 3 tables. Users , Posts, and Likes .
When I use JOIN (Posts+Users) everything works correctly.
But, when I connect MORE and the LIKES table, the data is duplicated by the number of likes to the table: Posts.
those. if a post has 15 likes, then that post will be selected 15 times.
Help solve the problem.
PS
Tables: Users - has a user_id (unique user ID) Posts- has a post_id, (unique post ID) and post_user (post author that links to users.user_id) and a Likes table that has only 3 columns (likes.like_user - like author, likes.like_id (object ID) and likes.like_object (object type - post, article, video or photo)
I hope I didn't write too vaguely. Thank you in advance)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question