I currently have a query that returns a list of every post that exists, its comments (concatenated), and how many likes it has.
I would like to include a column that that indicates whether or not the user has upvoted/liked this specific post. The structure of the relevant tables are as follows:
likes (id, elementID, googleID)
elements (id, googleID, time, title, body, type)
comments (id, elementID, googleID, body)
So how would I go through the likes, determine if one of them has the user's ID (dynamically put into the query via Node.JS), and then create a column indicating a simple true or false?
SELECT E.id, E.time, E.title, E.body, E.type, C.comments, E.googleID, L.likeCount
FROM elements E
LEFT JOIN(
SELECT elementID, GROUP_CONCAT(body SEPARATOR '|-|') AS comments
FROM comments
GROUP BY elementID
) C on C.elementID = E.id
LEFT JOIN (
SELECT elementID, COUNT(id) AS likeCount
FROM likes
GROUP BY elementID
) L ON L.elementID = E.id;