Saturday, 9 May 2015

Finding duplicate values in a SQL table

Today I tried to find all the duplicate data in specific column in the table

below is the simple query to find it out.



 if we have a table such below structure
 select * from student


| Student_Name | grade |
------------------------------
| Usama              |  A      |
|  Ahmed            |  B       |
|  Mohamed        |  A      |


if you want to how many student get in  every grad

you can use below query

SELECT
    grade, COUNT(*)
FROM
    student
GROUP BY
     grade
HAVING 
    COUNT(*) > 1

No comments:

Post a Comment