This seems so simple but I can't understand how do I do this query: I have a table users like this:
user_id | name | role
1 | abc | a
2 | lol | b
3 | f | c
and a table usersprojects (with user and project PKs)
projectid | userid
1 | 1
1 | 2
2 | 2
2 | 3
How could I select all users columns and also a boolean column alias "assigned" to project "1"
I would like a result like this:
user_id | name | role | assigned
1 | abc | a | true
2 | lol | b | true
3 | f | c | false
The query wouldn't be something like this:
Select user_id ,name, role,
(users.user_id in (Select user_id from usersprojects where projectid=1)
) assigned;
But it doesn't work... what is the right way to do this query?