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.
| Author |
Topic |
|
anishap
Yak Posting Veteran
61 Posts |
Posted - 2009-03-12 : 14:07:07
|
| Hi,I have an employee table and vaccine table. I would like to find out the duplicate vaccine records with same date and type from the below table.Vaccine table:Date: 01/01/2001Vaccine Type: InfluenzaDate: 03/20/1998Vaccine Type: Hepatitis BDate:01/01/2001Vaccine Type: InfluenzaDate:03/19/2002Vaccine Type: InfluenzaThe query should find out the above duplicate Influenza record with same date (01/01/2001)I tried the below query but it didn't workSELECT E.ID,E.LNAME,E.FNAME,I.DATE,I.TYPE FROM IMMUNE I,EMPLOYEE EWHERE E.REC_NUM = I.EMPLOYEEGROUP BY E.ID,E.LNAME,E.FNAME,I.DATE,I.TYPEHAVING COUNT(I.TYPE) > 1 AND COUNT(I.DATE)> 1Can anyone help me with this? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-03-12 : 14:12:40
|
| [code]SELECT Date,[Vaccine Type]FROM(SELECT ROW_NUMBER () OVER (PARTITION BY Date,[Vaccine Type] ORDER BT [Date]) AS Seq,Date,[Vaccine Type]FROM Table)tWHERE Seq>1[/code] |
 |
|
|
anishap
Yak Posting Veteran
61 Posts |
Posted - 2009-03-12 : 14:24:08
|
| I need to join employee and vaccine table. |
 |
|
|
anishap
Yak Posting Veteran
61 Posts |
Posted - 2009-03-12 : 14:34:34
|
| When I tried the above I'm getting incorrect syntax error |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-03-12 : 14:48:17
|
| The query looks fine. Whats the error you get ? Also, can you post the exact query you tried? |
 |
|
|
anishap
Yak Posting Veteran
61 Posts |
Posted - 2009-03-12 : 14:59:12
|
| I'm not getting any error. Now the below query is working fine. SELECT E.ID,E.LNAME,E.FNAME,I.DATE,I.TYPE FROM IMMUNE I,EMPLOYEE EWHERE E.REC_NUM = I.EMPLOYEEGROUP BY E.ID,E.LNAME,E.FNAME,I.DATE,I.TYPEHAVING COUNT(I.TYPE) > 1 AND COUNT(I.DATE)> 1Some how I didn't get any result when I tried before. Not sure what was the problem.Thanks for checking this. |
 |
|
|
|
|
|
|
|