I have a question from an assignment for database using sqlite3 or MySQL. The question is:
Find all the last names belonging to two or more presidents. Do not repeat a last name, and remember that the same person serving two different terms (e.g., Grover Cleveland) does not constitute a case of two presidents with the same last name.
SELECT lastName FROM Presidents GROUP BY lastName HAVING COUNT(lastName) > 1;
You want to select last names whose count of distinct first names is greater than one. This query does precisely this:
SELECT lastName FROM Presidents GROUP BY lastName HAVING COUNT(DISTINCT firstName) > 1
Follow the link below for a running demo: