79333829

Date: 2025-01-06 17:25:50
Score: 0.5
Natty:
Report link

I have managed to get it working. I was thinking in the first when case was a '1' when it is a 'l'. As the code was written by someone else who was helping and to be fair they look identical but thanks to @ADyson it now works well. I simply changed the 'l' for liked to a new 'v' for viewed. It may not be the most efficient way but it works.

   CASE 
        WHEN l.to_user IS NOT NULL THEN 'true'
        ELSE 'false'
    END AS isLiked,
    
        CASE 
        WHEN v.to_user IS NOT NULL THEN 'true'
        ELSE 'false'
    END AS hasViewed
    
FROM clients u

LEFT JOIN likes l 
    ON u.userID = l.to_user 
    AND l.from_user = '$logged_user'
    
    LEFT JOIN viewed v 
    ON u.userID = v.to_user 
    AND v.from_user = '$logged_user'

I would not mind any feedback to a better way of doing this if possible but I hope it helps someone struggling with the sample problem.

Reasons:
  • Blacklisted phrase (0.5): thanks
  • Whitelisted phrase (-1): hope it helps
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @ADyson
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: JulesUK