How To Count Duplicated Values in a Column?
Page 1 of 1
How To Count Duplicated Values in a Column?
If you have a column with duplicated values, and you want to know what are those duplicated
values are and how many duplicates are there for each of those values, you can use the GROUP
BY ... HAVING clause as shown in the following example. It returns how many duplicated first
names in the employees table:
SQL> SELECT first_name, COUNT(*) FROM employees
GROUP BY first_name HAVING COUNT(*) > 1;
FIRST_NAME COUNT(*)
-------------------- ----------
Peter 3
Michael 2
Steven 2
John 3
Julia 2
William 2
Karen 2
Kevin 2
values are and how many duplicates are there for each of those values, you can use the GROUP
BY ... HAVING clause as shown in the following example. It returns how many duplicated first
names in the employees table:
SQL> SELECT first_name, COUNT(*) FROM employees
GROUP BY first_name HAVING COUNT(*) > 1;
FIRST_NAME COUNT(*)
-------------------- ----------
Peter 3
Michael 2
Steven 2
John 3
Julia 2
William 2
Karen 2
Kevin 2
Similar topics
» How To Update Values in a Table?
» How To Use Existing Values in UPDATE Statements?
» How To Add a New Column to an Existing Table?
» How To Use SELECT Statement to Count the Number of Rows?
» How To Delete a Column in an Existing Table?
» How To Use Existing Values in UPDATE Statements?
» How To Add a New Column to an Existing Table?
» How To Use SELECT Statement to Count the Number of Rows?
» How To Delete a Column in an Existing Table?
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Sun Jan 31, 2010 12:35 am by Micheal
» Accessing tables of other users in SQL
Sun Jan 31, 2010 12:34 am by Micheal
» Grouping commands in SQL
Sun Jan 31, 2010 12:32 am by Micheal
» Operations on Result Sets in SQL
Sun Jan 31, 2010 12:31 am by Micheal
» Subqueries in SQL
Sun Jan 31, 2010 12:30 am by Micheal
» Joining Relations in SQL
Sun Jan 31, 2010 12:28 am by Micheal
» Delete comand in SQL
Sun Jan 31, 2010 12:27 am by Micheal
» Update command in SQL
Sun Jan 31, 2010 12:26 am by Micheal
» Insert command in SQL
Sun Jan 31, 2010 12:23 am by Micheal