Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving records fulfilling a condition using GROUP BY

I'd like to only select the rows where the count is greater than 1 (in other words the duplicates) right now from a few thousand records I am mostly seeing 1s with a few 2s and 3s here and there

SELECT count( * ) AS `Number` , GI . *
FROM `GeneralInformation` AS GI
GROUP BY `FirstName` , `Surname` 

how can I do this?

like image 463
Moak Avatar asked Jan 04 '10 02:01

Moak


2 Answers

SELECT count( * ) AS `Number` , GI . *
FROM `GeneralInformation` AS GI
GROUP BY `FirstName` , `Surname` 
HAVING count(*)>1
like image 58
Mike Tunnicliffe Avatar answered Oct 15 '22 04:10

Mike Tunnicliffe


Use the Having clause

SELECT count( * ) AS `Number` , GI . *
FROM `GeneralInformation` AS GI
GROUP BY `FirstName` , `Surname` 
HAVING count( * ) > 1
like image 35
mopoke Avatar answered Oct 15 '22 04:10

mopoke