Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 please help with SQL Query

Author  Topic 

Tamaradenise
Starting Member

7 Posts

Posted - 2014-12-24 : 23:13:23
Table PATIENT has columns PATIENT_ID, FNAME, and LNAME. Write a query that will identify duplicate PATIENT_IDs in the table PATIENT. The query should return all three columns and include all rows where the PATIENT_ID shows up more than once in the table.

Tamara

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-12-25 : 19:08:39
http://www.sqlteam.com/article/deleting-duplicate-records


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

MuralikrishnaVeera
Posting Yak Master

129 Posts

Posted - 2014-12-26 : 07:52:54
[code]
CREATE TABLE PATIENT (PATIENT_ID int,FNAME varchar(1024),LNAME varchar(1024))
INSERT INTO PATIENT
SELECT 1,'Jhon','kel' UNION ALL
SELECT 1 ,'Rute','Obriean' UNION ALL
SELECT 3 ,'james','steve' UNION ALL
SELECT 3 ,'Peter','Mac' UNION ALL
SELECT 3 ,'jack','rans' UNION ALL
SELECT 5 ,'rober','tom'

SELECT * FROM
(
SELECT *,COUNT(*)OVER(PARTITION BY (PATIENT_ID )) Cn
FROM PATIENT
)a
WHERE a.Cn > 1
[/code]

---------------
Murali Krishna

You live only once ..If you do it right once is enough.......
Go to Top of Page

Tamaradenise
Starting Member

7 Posts

Posted - 2014-12-26 : 16:20:17
Thank yall for the help

Tamara
Go to Top of Page
   

- Advertisement -