I'm working on a SQL-statement which will involve 3 different tables. Below you can see the structure of them with one example data each.
- FOLLOWERS-TABLE: This table contains information about the current user ('user') following another user ('following')
- MESSAGES: This table contains information about messages of a certain user
- LIKES: This table contains information about who liked other messages. 'idmessage' is the same as the 'id' in the Messages-table
First of all, I wanted to display all the messages of the persons who the user follows. I used this query:
SELECT *
FROM Messages
LEFT JOIN Followers ON Followers.following=Messages.user
WHERE Followers.user = 'Peter Jackson'
This resulted in this:
It is working. However, in the next step I should add a custom column to it, this must be 'alreadyLiked'. This should check if the user already liked the message. The value must be 'yes' or 'no'. Therefore, information about the Likes-table is needed. I guess I should make another join on 'Likes.idmessage' and 'Messages.id'. But I don't know how to give it a value 'yes' or 'no'. In the end, it should be like this:

On the server-side I use Node.js and the client-side AngularJS.

