When you need to show values in a SQL table (RDBMS) with an objective to display values which are duplication, and summarize the same value by count it as a numeric. So, you have to write SQL statement and execute it as an example follow;

Table name “ExamResults”

IdStudentGrade
1Steven3.5
2Dave3.7
3Ryan3.25
4Jamie4.0
5Eric3.5
6Robbie4.0
7Peter4.0
8John3.25
9Gary4
10Roy2.85

Above table you will see a student with their grade. So, we need to find “how many students who are get grade 4 in the class?”. This question can be responded with our objective to find duplicated values in a table. You have to design your SQL statement using SELECT & GROUP function as follow;

SELECT field_name, COUNT(field_name) AS icount
FROM TABLE_NAME
GROUP BY field_name

to be

SELECT Grade, COUNT(Grade) AS icount
FROM ExamResults
GROUP BY Grade

Result

Gradeicount
3.52
3.71
3.252
44
2.851

This results will tell us how many student each of grades. The number 1 in a column of “icount” is mean to no student in a class which get that grade more than one people, unduplication.

Additional,  you can specify to see only a duplicated values in the table by define HAVING function  as follow;

SELECT Grade, COUNT(Grade) AS icount
FROM ExamResults
GROUP BY Grade
HAVING COUNT(Grade) > 1

Result

Gradeicount
3.52
3.252
44

Moreover, if you need to see the duplicated value under  your conditions, you can use WHERE as a condition in your statement as follow;

SELECT Grade, COUNT(Grade) AS icount
FROM ExamResults
WHERE Grade<4
GROUP BY Grade
HAVING COUNT(Grade) > 1

Result

Gradeicount
3.522
3.252

NOTE: SQL statements in this content are fine to execute in MSSQL, but can be applied to use in the other, i.e. MySQL, PostgresQL etc.

1 Can I have some encouragement?
(Visited 54 times, 1 visits today)