Two tables, shop_1 and shop_2, have the same customer_id and customer_name columns. Write a query that returns customers who appear in both.

Finding customers present in both shop_1 and shop_2 is a classic set-intersection problem. It can be solved with an INNER JOIN on customer_id (portable across all databases) or with the INTERSECT operator (simpler syntax, but not supported by MySQL).

Key Points

Example

If shop_1 and shop_2 both list "Alice" as a customer, an INNER JOIN on customer_id between the two tables returns her name once in the result set, while customers unique to only one shop are excluded.

-- Using INNER JOIN (works everywhere, including MySQL)
SELECT DISTINCT s1.customer_name
FROM shop_1 s1
JOIN shop_2 s2 ON s1.customer_id = s2.customer_id;

-- Using INTERSECT (not available in MySQL)
SELECT customer_name FROM shop_1
INTERSECT
SELECT customer_name FROM shop_2;

Interview Tip

A concise interview answer is

I'd join shop_1 and shop_2 on customer_id and select the distinct customer_name, which works on any database. If the database supports it, INTERSECT is a cleaner way to express the same intent, but MySQL didn't support it until fairly recent versions, so the JOIN approach is the safer default.

Last updated: 11 November 2026

Previous question: Can you have an index on a view? If yes, how?

Next question: What is the difference between INNER JOIN and OUTER JOIN?

More SQL interview questions

All SQL questions