"Write a query to find duplicate 'name' values in a 'user' table"
I had to think about this for a few minutes. It's really easy to suppress duplicates. But returning only duplicates is not so obvious. Here's the answer I gave.
After getting home a quick test with my local copy of MySQL revealed my answer was indeed correct. As an added bonus you also get the number of times each value appears.select
name,
count(name) as name_count
from
users
group by
name
having
name_count > 1;
No comments:
Post a Comment