What is the difference between using DISTINCT and using GROUP BY with HAVING COUNT > 1 in SQL queries?
💡 Model Answer
DISTINCT removes duplicate rows from the result set. It compares all selected columns and keeps only one copy of each unique row. GROUP BY with HAVING COUNT > 1 groups rows by the specified column(s) and returns only those groups that have more than one row, effectively identifying duplicates. DISTINCT is a set operation that works on the entire row, while GROUP BY can be used to aggregate data, count duplicates, and perform calculations. For example, SELECT DISTINCT FROM students removes exact duplicate rows. SELECT student_name, COUNT() FROM students GROUP BY student_name HAVING COUNT(*) > 1 returns the names that appear more than once along with their counts.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI — Starts at ₹500