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 |
|
reacha
Starting Member
49 Posts |
Posted - 2010-12-08 : 14:20:47
|
| I have a table called Auditlog in which i have fieldspkgid,queueid,userid,audittype,auditstampI need to write the self join on this tableso that when audittype,queueid,pkgid are same for two rows and audittype = 15i only need to get that rows in my selfjoin but when i tried doing so i am getting more columns in the output.if for ex: pkgid queueid,audittype 100, 5 15 100 5 15 101 10 5 102 20 15 102 20 15output should be 100 5 15 100 5 15 102 20 15 102 20 15but i am getting 100 5 15 100 5 15 100 5 15 100 5 15 102 20 15 102 20 15Please helpme out!!Thanks,reacha |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2010-12-08 : 16:44:03
|
| select t.*from tbl tjoin(select pkgid, queueidfrom tblwhere audittype = 15group by pkgid queueidhaving count(*) = 2) aon t.pkgid = a.pkgid and t.queueid = a.queueidand t.audittype = 15==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
reacha
Starting Member
49 Posts |
Posted - 2010-12-08 : 17:59:29
|
| i got the correct output..Thanks very much for your helpThanks,reacha |
 |
|
|
|
|
|