So let's say that this is the `likes` table that can like either `comments` or `posts`, here are some queries:
// Get comments and their respective likes
SELECT * from comments
JOIN likes ON comments.id = likes.reference_id;
// Get posts and their respective likes
SELECT * from posts
JOIN likes ON posts.id = likes.reference_id;
// Get likes and their referenced comments
SELECT * from likes
JOIN comments ON comments.id = likes.reference_id;
So this is for the structure with the two columns
So let's say that this is the `likes` table that can like either `comments` or `posts`, here are some queries: And so on.