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 |
|
tpiazza55
Posting Yak Master
162 Posts |
Posted - 2008-05-05 : 09:48:12
|
| I am trying to create a query that will find all the records that have the same value multiple times in the a column called phonenumber.How do i return disticnt records having count greater than 1 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-05-05 : 09:52:54
|
| [code]select phonenumber, count(*)from tablegroup by phonenumberhaving count(*)>1[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-05 : 10:47:11
|
| And if you want to retrieve all details use the above query as a subquerySELECT * from table where phonenumber in (select phonenumber, count(*)from tablegroup by phonenumberhaving count(*)>1) |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-05-05 : 11:02:37
|
quote: Originally posted by visakh16 And if you want to retrieve all details use the above query as a subquerySELECT * from table where phonenumber in (select phonenumber count(*)from tablegroup by phonenumberhaving count(*)>1)
Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
vivekroberts
Starting Member
2 Posts |
Posted - 2008-05-08 : 04:01:17
|
| select * from YourTablewhere phonenumber not in (select distinct phonenumber from YourTable group by phonenumber having count(phonenumber)=1 ) |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-05-08 : 04:23:09
|
quote: Originally posted by vivekroberts select * from YourTablewhere phonenumber not in (select distinct phonenumber from YourTable group by phonenumber having count(phonenumber)=1 )
You dont need to use DISTINCT as you use GROUP BY ClauseMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|