SQL query for finding pairs of rows with same value for column C

Write a SQL query to find all pairs of rows (a, b) such that a is in table A, b is in table B, and a and b have the same value for column C.

Problem

Given two tables, A and B, write a SQL query to find all pairs of rows (a, b) such that:
- a is in table A
- b is in table B
- a and b have the same value for column C
Example input:
Table A:
| id | value |
|----|-------|
| 1  | 10    |
| 2  | 20    |
| 3  | 30    |
Table B:
| id | value |
|----|-------|
| 4  | 10    |
| 5  | 30    |
| 6  | 40    |
Example output:
| a  | b  |
|----|----|
| 1  | 4  |
| 2  | 4  |
| 3  | 5  |

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
SELECT a.id, b.id
FROM A a
JOIN B b
ON a.value = b.value

A.I. Evaluation of the Solution

This solution is correct and demonstrates a good understanding of SQL. The approach is straightforward and easy to follow.

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