Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

why the query show only duplicated rows with 2 rows only?

I need to select all patients files with duplicated id no for example I have 5 files
using same id no and 20 files using same id no ,

I tried the following SELECT statement :

SELECT  patient_no  , id_no  , COUNT(*) 
FROM MR_PATIENT_IDS 
GROUP BY patient_no , id_no
HAVING COUNT(*) > 1

but the output show only id_no duplicated 2 times and not show the greater than 2

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

what is the missing in the query ?

>Solution :

The subquery will include all duplicated id_no. (with multiple patient_no)

Then, you use join to get your list of patient_no + id_no.

See db<>fiddle

SELECT t1.patient_no, t1.id_no
FROM MR_PATIENT_IDS t1
INNER JOIN (
  SELECT id_no, COUNT(*) AS count
  FROM MR_PATIENT_IDS 
  GROUP BY id_no
  HAVING COUNT(*) > 1
) t2 ON t1.id_no = t2.id_no
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading