jeudi 9 avril 2015

if any data duplicate then output show 1 if not then show 0 in sql server

Hi Friends I have small doubt in sql server how to solve this issue Table: emp



id| name| sal
1| abc| 100
2| ha| 200
1| abc| 100
1| abc| 100
1| abc| 100
2| ha| 200
2| ha| 200
3 hai| 400


based on this data I want give data duplicate or not in the table for that status i out show output. I tried like below



select count(*)as status

from [Test].[dbo].[emp]
group by [id]
,[name]
,[sal]

having count(*)>=1
order by count(*) desc


that time i got output



status
4
3
1


I donot want get output like above way.


I want show output like below



Status
1


when data comes unique in table that time status shows : 0 values. 1 means duplicate data and o means unique records.please tell me how to get singe status values to achive this issue.


Aucun commentaire:

Enregistrer un commentaire