SQL Query to Find Common Records Between Two Tables

This technical problem deals with finding common records between two SQL tables. An example is given, along with the expected output.

Problem

Given two tables, A and B, write a SQL query to find the common records between the two tables.
Example input:
A:
id | name
1 | John
2 | Doe
3 | Smith
4 | Jane
B:
id | name
1 | John
2 | Smith
3 | Jane
4 | Doe
5 | Johnson
Example output:
id | name
1 | John
2 | Smith
3 | Jane
4 | Doe

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
SELECT A.id, A.name
FROM A
INNER JOIN B
ON A.id = B.id
AND A.name = B.name;

/*

The above solution is optimal because it uses an inner join to find the common records between the two tables.

*/

A.I. Evaluation of the Solution

The candidate's solution is correct and uses an inner join, which is the most efficient way to find common records between two tables.

Evaluated at: 2023-01-31 04:15:25