Chapter 5 · JOINs
40. Customer Pairs in the Same City
Medium20 XPFinance
The networking team wants to find pairs of customers who live in the same city. Return customer1_name (first_name || ' ' || last_name), customer2_name, and city. Ensure each pair appears only once (customer1 id < customer2 id). Sort by city, then customer1_name, then customer2_name. Limit to 50.
Tables
- PKidINT
- first_nameTEXT
- last_nameTEXT
- emailTEXT
- phoneTEXT
- date_of_birthTEXT
- cityTEXT
- stateTEXT
- countryTEXT
- created_atTIMESTAMP
Need help?
Ask Sol
AI tutor — looks at your current query and nudges you, without spoiling the answer.
Solution
Try the hints first — solving it yourself is what makes it stick.