Say I have the following table:
create table ratings (
user_id int unsigned not null,
post_id int unsigned not null,
rating set('like','dislike'),
primary key (user_id, post_id)
);
And two users, with ids 1 and 2. I want to find out how much they agree in their ratings, so what I need is a way to select all the posts that both users rated, together with the rating of each user towards each post. Something like:
+---------+---------+---------+
| post_id | rating1 | rating2 |
+---------+---------+---------+
| 1 | like | dislike |
| 2 | like | like |
| 5 | like | dislike |
| 6 | dislike | dislike |
+---------+---------+---------+
Any clue is appreciated, thanks!
Join your ratings table on itself within post id, and select the rating from each table, restricting the user: