Find customers with at least one order in each table

Given two tables, this SQL query finds all customers who have at least one order in each table.

Problem

Given two tables, write a SQL query to find all the customers who have at least one order in each table.
Input:
Table 1:
customer_id | order_id
1 | 100
2 | 101
3 | 102
4 | 103
5 | 104
6 | 105
7 | 106
8 | 107
9 | 108
10 | 109
Table 2:
customer_id | order_id
1 | 200
2 | 201
3 | 202
4 | 203
5 | 204
6 | 205
7 | 206
8 | 207
9 | 208
10 | 209
Output:
customer_id
1
2
3
4
5
6
7
8
9
10

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
SELECT customer_id
FROM table1
WHERE customer_id IN (SELECT customer_id FROM table2)

/*

The solution above is optimal because it uses the IN operator to check if the customer_id from table1 is in table2.

*/

A.I. Evaluation of the Solution

The solution above is optimal because it uses the IN operator to check if the customer_id from table1 is in table2.

Evaluated at: 2022-11-21 08:16:20