Question

SELECT REPLACE( nokp,  '-',  '' ) AS kp, nama, COUNT( id ) 
FROM participants
GROUP BY kp
HAVING COUNT( * ) >1

this is my sql statement to find the duplicate data. but actually i want to view all data in that row that have duplicate nokp. (SELECT *) and view data that have duplicate nokp.

EDIT.. I have done what exactly i want to view.

SELECT REPLACE( nokp,  '-',  '' ) AS kp1, nama, daerah, parlimen, dun, pbt, mukim, alamat, telefon, j_kerja
FROM participants
WHERE REPLACE( nokp,  '-',  '' ) 
IN (

SELECT REPLACE( nokp,  '-',  '' ) AS kp
FROM participants
GROUP BY kp
HAVING COUNT( * ) >1
)
ORDER BY  `kp1` ASC 
Était-ce utile?

La solution

Try this:

Select *
From participants
Where nokp in
(
  Select nokp
  From participants
  Group by nokp
  Having count(*) > 1
 )

This will give you the all the rows with duplicate values.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top