| Author |
Topic |
|
msvdm
Starting Member
17 Posts |
Posted - 2011-07-28 : 10:53:56
|
| What query determines the entire redundancies present in the table. |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-07-28 : 10:57:39
|
This will show the list of col1 and col2 combination that exist more than once in your table.select col1, col2from YourTablegroup by col1, col2having count(*) > 1 |
 |
|
|
msvdm
Starting Member
17 Posts |
Posted - 2011-07-28 : 11:15:40
|
| Thanks for your valuable replyI want to know the redundancies of all the columns in the table. When I select all the columns and include them in the group by I am not able to see or get the data if I use the same syntax as above. |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2011-07-28 : 11:21:35
|
quote: Originally posted by msvdm What query determines the entire redundancies present in the table.
Since you didn't provide your table structure, sample data or expected output it's hard to tell what you mean by "entire redundancies." Perhaps this link will help you to prove your DDL, DML and expected out so we can better answer your question:http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx |
 |
|
|
msvdm
Starting Member
17 Posts |
Posted - 2011-07-28 : 11:25:54
|
| Thanks for your valuable replyselect col1,col2,.......col8from Mytablegroupbycol1,col2,.....col8havingcount(*)>1 |
 |
|
|
msvdm
Starting Member
17 Posts |
Posted - 2011-07-28 : 11:56:28
|
| I am unable to see the data when I do the followingselectTyeId,YId,Rate,IndicId,Ra,RolId,Approv,PpIdgroup byTyeId,YId,Rate,IndicId,Ra,RolId,Approv,PpIdhavingcount(*) > 1 |
 |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-07-28 : 12:26:19
|
quote: Originally posted by msvdm I am unable to see the data when I do the followingselectTyeId,YId,Rate,IndicId,Ra,RolId,Approv,PpIdgroup byTyeId,YId,Rate,IndicId,Ra,RolId,Approv,PpIdhavingcount(*) > 1
The query is going to look for the combination of all 8 columns to see if there are any that are exactly identical. If there are none, you will not get any rows in the result. This example might help - here, I am looking for unique combination of col1 and col2. There are 2 such combinations: CREATE TABLE #tmp (col1 INT, col2 INT, col3 INT);INSERT INTO #tmp SELECT 1,1,1 UNION ALLSELECT 1,1,2 UNION ALLSELECT 1,2,1 UNION ALLSELECT 2,1,1 UNION ALLSELECT NULL,1,1 UNION ALLSELECT NULL,1,3;SELECT col1, col2FROM #tmpGROUP BY col1, col2HAVING COUNT(*) > 1 DROP TABLE #tmp; |
 |
|
|
|
|
|