How To Count Duplicated Values in a Column in MS SQL Server?
Submitted by: AdministratorIf 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 ggl_team table:
SELECT first_name, COUNT(*) FROM ggl_team
GROUP BY first_name HAVING COUNT(*) > 1
GO<pre>
first_name count(*)
John 5</pre>
So we have "John" as duplicated first name 5 times in the ggl_team table.
Submitted by: Administrator
SELECT first_name, COUNT(*) FROM ggl_team
GROUP BY first_name HAVING COUNT(*) > 1
GO<pre>
first_name count(*)
John 5</pre>
So we have "John" as duplicated first name 5 times in the ggl_team table.
Submitted by: Administrator
Read Online MS SQL Server Job Interview Questions And Answers
Top MS SQL Server Questions
☺ | How To Start SQL Server Browser Service? |
☺ | How to create new table with "CREATE TABLE" statements? |
☺ | How To Execute the Cursor Queries with "OPEN" Statements? |
☺ | What Happens If Strings Are Casted into Wrong Code Pages in MS SQL Server? |
☺ | PHP MSSQL - How To Display a Past Time in Days, Hours and Minutes? |
Top Databases Programming Categories
☺ | RDBMS Interview Questions. |
☺ | SQL Interview Questions. |
☺ | SSRS Interview Questions. |
☺ | Database Administrator (DBA) Interview Questions. |
☺ | Sybase Interview Questions. |