SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 getting the right data only
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ppatel112
Starting Member

19 Posts

Posted - 07/11/2012 :  01:43:26  Show Profile  Reply with Quote
Hi there,

i have a following query:
SELECT rowno,elink_entityid,ELink_RecordID,ELink_Type,* FROM
(SELECT * ,
ROW_NUMBER() OVER(PARTITION BY emai_emailaddress,Elink_recordid ORDER BY emai_emailaddress,Elink_recordid DESC) as rowno
FROM dbo.email LEFT JOIN emaillink ON elink_emailid = Emai_EmailId
where Emai_emailaddress in (select Emai_emailaddress from email LEFT JOIN emaillink ON elink_emailid = Emai_EmailId
GROUP BY Emai_emailaddress, ELink_RecordID HAVING ((count(Emai_emailaddress)>1) and (count(Elink_recordid)>=1)))
) as Duplicates

that returns below:
rowno,elink_entityid,ELink_RecordID,ELink_Type
1 5 1348 Business 3321
1 13 2051 Business 3306
1 13 2069 Business 3308
1 13 2078 Business 3311
1 13 2121 Business 3320
2 13 2121 Private 3404
1 13 2125 Business 3322

what is just need is elink_recordid 2121 and not the rest.

how can i acheive this?

regards

lionofdezert
Aged Yak Warrior

Pakistan
864 Posts

Posted - 07/11/2012 :  04:25:19  Show Profile  Visit lionofdezert's Homepage  Send lionofdezert a Yahoo! Message  Reply with Quote
Just place where clause at the end of your query (Whats worng )
WHERE elink_recordid = 2121

--------------------------
http://connectsql.blogspot.com/
Go to Top of Page

webfred
Flowing Fount of Yak Knowledge

Germany
8514 Posts

Posted - 07/11/2012 :  05:10:48  Show Profile  Visit webfred's Homepage  Reply with Quote
looks like the solution is to just delete the equal sign here:
and (count(Elink_recordid)>=1)))


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47099 Posts

Posted - 07/11/2012 :  10:09:10  Show Profile  Reply with Quote
is it all 2121 records irrespective of other conditions or do you've other logic to apply as well?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000