The problem is very similar to the stack exchange voting system. I’d like to query an object table for a random object and also get back any votes a specified user has on that object.
objects table:
id
user_id
message
votes table:
object_id
user_id
vote_value
select * from objects order by RAND() produces a random object, but how can I select a specific user’s vote value for that object in the same query? It’s possible that the user never votes on the result object so I can’t simply do a join on id/object_id.
This query will print
NULLforuser_idandvote_valueif the user (in this case1) didn’t vote on an object: