SQL query to find all users who have the permission to view a certain resource

Given two tables - one of users and one of permissions - write a SQL query to find all users who have the permission to view a certain resource.

Problem

Given a table of users and a table of permissions, write a SQL query to find all users who have the permission to view a certain resource.
Example input:
users:
id | name
1 | John
2 | Jane
3 | Bob
permissions:
user_id | resource
1 | resource1
1 | resource2
2 | resource2
3 | resource1
Example output:
id | name
1 | John
2 | Jane

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
SELECT users.id, users.name
FROM users
JOIN permissions ON users.id = permissions.user_id
WHERE permissions.resource = 'resource2';

/*

The solution above is optimal because it uses a JOIN to combine the two tables and then filters the results to only include the users who have the permission to view the resource.

*/

A.I. Evaluation of the Solution

The candidate's solution is correct and demonstrates a good understanding of SQL. The solution is also efficient, using a JOIN to combine the two tables and then filtering the results.

Evaluated at: 2022-11-09 10:15:17