Reputation: 79
I have two tables discussions
and votes
that are like this
discussions
votes
that parentId in votes is id in discussions table
but exist a problem
I want to have a key with name likeByMe
and want to fill this key when select discussions for specific user.
how can I connect these two tables and fill this value when call one query?
I want something like this
select *
from discussions
and fill likeByMe from votes table for any rows by true or false value
Upvotes: 0
Views: 468
Reputation: 1270873
Given your description, you can use exists
:
select d.*,
(exists (select 1
from votes v
where v.parentid = d.id and v.userid = ?
)
) as likedByMe
from discussions d;
The ?
is a parameter placeholder for the user you care about.
Upvotes: 0