jeudi 9 avril 2015

if any duplicate data in table then status show 1 of all data unique in table then status show o in sql server

I have small question about 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 this:



select case when count(*)>1 then 1 else 0 end as 'Status'from emp group by id,name,sal


I get this output:



status
1
1
0


I do not 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 value only


1 means duplicate data and o means unique records in that table. if any records have duplicate finaly output show one(1) only .no need to display corresponding duplicate values status show 1 .If all records unique in that table I want display only 0(zero). no need to display corresponding unique value status please tell me how to get singe status values to achive this issue.


Aucun commentaire:

Enregistrer un commentaire