SELECT p1.first_name as p1_first, p2.first_name as p2_first, p1.city, p1.allergies FROM patients p1 JOIN patients p2 ON p1.city = p2.city AND p1.allergies = p2.allergies AND p1.patient_id < p2.patient_id WHERE p1.allergies IS NOT NULL;
Write your query and click "Run Query" (Ctrl + Enter) to see results and testcase validation.