Author |
Topic |
RoniDxb
Starting Member
28 Posts |
Posted - 2008-08-02 : 18:46:05
|
Table1 A......B...................................1......Mouse................................2......Keyboard.............................3......Printer..............................2......Keyboard.............................1......Mouse................................1st . I want to select all those rows which are duplicate for example in Table1 it will be like1......Mouse................................1......Mouse................................2......Keyboard.............................2......Keyboard.............................2nd.Select all those rows which are not duplicate for example in Table1 it will be like3......Printer..............................plz guide me |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-08-02 : 19:52:35
|
1. SELECT A, B, COUNT(*) FROM Table1 GROUP BY A, B HAVING COUNT(*) > 12. SELECT A, B FROM Table1 GROUP BY A, B HAVING COUNT(*) = 1Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
RoniDxb
Starting Member
28 Posts |
Posted - 2008-08-03 : 18:56:18
|
quote: Originally posted by tkizer 1. SELECT A, B, COUNT(*) FROM Table1 GROUP BY A, B HAVING COUNT(*) > 12. SELECT A, B FROM Table1 GROUP BY A, B HAVING COUNT(*) = 1Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog
Tara Kizer The solution you have written just tells us how many rows are duplicate it does not show all duplicate rows for example the solution you have written shows result if we apply on above table11. A.......B............. (No columne Name)2.......KeyBoard...... 21.......Mouse......... 2but i want it should shows likeA......B1......Mouse................................1......Mouse................................2......Keyboard.............................2......Keyboard............................. |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
rmiao
Master Smack Fu Yak Hacker
7266 Posts |
Posted - 2008-08-03 : 19:29:15
|
Take look at 'Using the FROM Clause' in books online. |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
RoniDxb
Starting Member
28 Posts |
Posted - 2008-08-04 : 04:28:13
|
Tara Kizer I am using sql 2000.I am sorry i have put this topic on 2005 too.Now i have known my forum is this.I am sorry again for this.my problem wan not solved yet. the solution you have written just tells us how many rows are duplicate.It does not take out all duplicate rows.i was in a big trouble bcoz of this i have put this topic on 2005 forum. i am sorry for that.actually i need the solution urgently.plz tell me anthor solution.plz Note i am beginner in sql so plz tell me solutoin as easy as possible. |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-08-04 : 04:45:02
|
Try thisSELECT t1.* FROM Table1 as t1 INNER JOIN(SELECT A, B, COUNT(*) FROM Table1 GROUP BY A, B HAVING COUNT(*) > 1) as t2 on t1.A=t2.A and t1.B=t2.BMadhivananFailing to plan is Planning to fail |
 |
|
RoniDxb
Starting Member
28 Posts |
Posted - 2008-08-04 : 06:48:32
|
MadhivananI have tried this but it gives the following errorNo column was specified for column 3 of 't2'. |
 |
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-08-04 : 06:50:59
|
you need a column alias for the count(*) in the subquery...SELECT t1.* FROM Table1 as t1 INNER JOIN(SELECT A, B, COUNT(*) as C FROM Table1 GROUP BY A, B HAVING COUNT(*) > 1) as t2 on t1.A=t2.A and t1.B=t2.BEm |
 |
|
RoniDxb
Starting Member
28 Posts |
Posted - 2008-08-04 : 07:16:11
|
Yessssss it worksThanks a lot |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-08-04 : 08:34:18
|
quote: Originally posted by elancaster you need a column alias for the count(*) in the subquery...SELECT t1.* FROM Table1 as t1 INNER JOIN(SELECT A, B, COUNT(*) as C FROM Table1 GROUP BY A, B HAVING COUNT(*) > 1) as t2 on t1.A=t2.A and t1.B=t2.BEm
Thanks. I forgot to specify it. I always name it as counting MadhivananFailing to plan is Planning to fail |
 |
|
|