﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / SQL Server Newbies  / Selecting very specific records ... / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Fri, 24 May 2013 15:06:51 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Selecting very specific records ...</title><link>http://www.sqlservercentral.com/Forums/Topic1421404-1292-1.aspx</link><description>Thank you ... that did it!-Mike</description><pubDate>Tue, 19 Feb 2013 07:19:10 GMT</pubDate><dc:creator>mikeallenbrown</dc:creator></item><item><title>RE: Selecting very specific records ...</title><link>http://www.sqlservercentral.com/Forums/Topic1421404-1292-1.aspx</link><description>You can use ROW_NUMBER() to achieve the desired results[code="sql"]SELECT	*FROM	(		SELECT	ROW_NUMBER() OVER ( PARTITION BY Client.ID, Patient.SSN ORDER BY StartOfCare ) AS RN,			Client.ID, Client.ClientName, Patient.ClientID, Patient.SSN, Patient.StartOfCare, Patient.PrimDiag		FROM	Client Client		INNER JOIN Patient Patient ON Client.ID = Patient.ClientID		WHERE	Patient.RptYear = 2012 AND Patient.PrimDiag &amp;lt;&amp;gt; 'NULL' AND Patient.PrimDiag &amp;lt;&amp;gt; '' AND Patient.SSN &amp;lt;&amp;gt; ''	) PWHERE	P.RN &amp;gt; 1[/code]</description><pubDate>Tue, 19 Feb 2013 00:26:55 GMT</pubDate><dc:creator>Kingston Dhasian</dc:creator></item><item><title>Selecting very specific records ...</title><link>http://www.sqlservercentral.com/Forums/Topic1421404-1292-1.aspx</link><description>In another thread I had a query where I needed to select only patient new admissions. The query finds the first entry per patient (per SSN actually) and ignores the rest. You can see that here: http://www.sqlservercentral.com/Forums/Topic1421364-1292-1.aspxWhat I need now is to select only re-admissions. So basically excluding the FIRST entry for a patient. If a patient was entered only once then that record is not selected at all.Here is the data:[IMG]http://i132.photobucket.com/albums/q18/mikeallenbrown/Public%20Album/Ashampoo_Snap_20130218_19h57m39s_013__zps9eda67f5.png[/IMG]Based off of the above data I'd expect to see ONLY line 5 and 7 .... patient with SSN of 123-12-3123 just happens to be the only duplicates in this sample but in a live database there could be many duplicates. Line 8 is the first admit so it too is excluded.Does that make sense? ....please let me know if further clarification is need. I wouldn't consider myself an "advanced" SQL use but I'm learning fast! :-DThank you in advance.-Mike</description><pubDate>Mon, 18 Feb 2013 19:12:47 GMT</pubDate><dc:creator>mikeallenbrown</dc:creator></item></channel></rss>