ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Select Distinct latest updated value in SQL Server<p>Hi <a class="username" rel="meetsree83">meetsree83</a>,</p> <p>Will you let us know what is condtion means on which basis condition you are looking this output ?</p>https://www.aspforums.net:443/Threads/921295/Select-Distinct-latest-updated-value-in-SQL-Server/https://www.aspforums.net:443/Threads/921295/Select-Distinct-latest-updated-value-in-SQL-Server/Mon, 17 Jun 2019 00:12:37 GMTSelect Distinct latest updated value in SQL Server<p>Based on the NO we will get duplicate records.If 2 records come for same NO,then we need one record with latest modifications implemented on the rows.</p> <p>For example:If MOb NO chnaged the the new mob no will be fetch and gave the o/p as one record.</p>https://www.aspforums.net:443/Threads/921295/Select-Distinct-latest-updated-value-in-SQL-Server/https://www.aspforums.net:443/Threads/921295/Select-Distinct-latest-updated-value-in-SQL-Server/Mon, 17 Jun 2019 00:34:01 GMTSelect Distinct latest updated value in SQL Server<p>Based on your record there are duplicate rows with only Date. So how can we identify the last updated record.</p> <p>You need to save Date with Time inorder to identify the last updated record.</p>https://www.aspforums.net:443/Threads/921295/Select-Distinct-latest-updated-value-in-SQL-Server/https://www.aspforums.net:443/Threads/921295/Select-Distinct-latest-updated-value-in-SQL-Server/Mon, 17 Jun 2019 02:19:47 GMTSelect Distinct latest updated value in SQL Server<p>UPDATE value is the&nbsp;latest modifications data.</p>https://www.aspforums.net:443/Threads/921295/Select-Distinct-latest-updated-value-in-SQL-Server/https://www.aspforums.net:443/Threads/921295/Select-Distinct-latest-updated-value-in-SQL-Server/Mon, 17 Jun 2019 02:34:53 GMTSelect Distinct latest updated value in SQL Server<p>Hi <a class="username" rel="meetsree83">meetsree83</a>,</p> <p>Refer below sample query.</p> <p><span style="text-decoration: underline;"><strong>SQL</strong></span></p> <pre class="brush: sql">DECLARE @TestTable AS TABLE(SiNo INT, [Action] VARCHAR(20),[No] INT, Mob INT, Email VARCHAR(50), [Status] INT, [Date] DATETIME) INSERT INTO @TestTable VALUES(1,&#39;ADD&#39;,123,1542,&#39;a@f.com&#39;,0,&#39;2019/6/16&#39;) INSERT INTO @TestTable VALUES(2,&#39;ADD&#39;,1563,1425,&#39;b@f.com&#39;,0,&#39;2019/6/16&#39;) INSERT INTO @TestTable VALUES(3,&#39;ADD&#39;,111,123,&#39;e@f.com&#39;,0,&#39;2019/6/17&#39;) INSERT INTO @TestTable VALUES(4,&#39;ADD&#39;,222,1234,&#39;f@f.com&#39;,0,&#39;2019/6/17&#39;) INSERT INTO @TestTable VALUES(5,&#39;UPDATE&#39;,222,12345,&#39;f@f.com&#39;,0,&#39;2019/6/17&#39;) INSERT INTO @TestTable VALUES(6,&#39;ADD&#39;,333,12345,&#39;r@f.com&#39;,0,&#39;2019/6/17&#39;) INSERT INTO @TestTable VALUES(7,&#39;UPDATE&#39;,333,1256,&#39;tt@f.com&#39;,0,&#39;2019/6/17&#39;) SELECT &#39;ADD&#39;[Action],[No],Mob,Email FROM ( Select *,ROW_NUMBER() OVER (PARTITION BY [No] ORDER BY [Action] DESC)rowNumber &nbsp; FROM @TestTable )t WHERE t.rowNumber = 1 ORDER BY SiNo</pre> <p><span style="text-decoration: underline;"><strong>Output</strong></span> </p> <table border="1"> <tbody> <tr style="height: 15.0pt;"> <td style="height: 15.0pt; width: 48pt;" width="64" height="20"><strong>Action</strong></td> <td style="width: 48pt;" width="64"><strong>No</strong></td> <td style="width: 48pt;" width="64"><strong>Mob</strong></td> <td style="width: 48pt;" width="64"><strong>Email</strong></td> </tr> <tr style="height: 15.0pt;"> <td style="height: 15.0pt;" height="20">ADD</td> <td align="right">123</td> <td align="right">1542</td> <td>a@f.com</td> </tr> <tr style="height: 15.0pt;"> <td style="height: 15.0pt;" height="20">ADD</td> <td align="right">1563</td> <td align="right">1425</td> <td>b@f.com</td> </tr> <tr style="height: 15.0pt;"> <td style="height: 15.0pt;" height="20">ADD</td> <td align="right">111</td> <td align="right">123</td> <td>e@f.com</td> </tr> <tr style="height: 15.0pt;"> <td style="height: 15.0pt;" height="20">ADD</td> <td align="right">222</td> <td align="right">12345</td> <td>f@f.com</td> </tr> <tr style="height: 15.0pt;"> <td style="height: 15.0pt;" height="20">ADD</td> <td align="right">333</td> <td align="right">1256</td> <td>tt@f.com</td> </tr> </tbody> </table>https://www.aspforums.net:443/Threads/921295/Select-Distinct-latest-updated-value-in-SQL-Server/https://www.aspforums.net:443/Threads/921295/Select-Distinct-latest-updated-value-in-SQL-Server/Mon, 17 Jun 2019 08:49:20 GMTSelect Distinct latest updated value in SQL Server<p>Dear ,</p> <p>The query provided is not worth for my query.</p> <p>&nbsp;</p> <p>For example for NO 222 2 records available.</p> <table style="width: 336pt; border-collapse: collapse;" border="0" width="448" cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 15pt;"> <td style="border-width: 0px 0.5pt 0.5pt; border-style: none solid solid; border-color: black windowtext windowtext; height: 15pt; background-color: transparent;" align="right" height="20"><font size="3" color="#000000" face="Calibri">4</font></td> <td style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: black windowtext windowtext black; background-color: transparent;"><font size="3" color="#000000" face="Calibri">ADD</font></td> <td style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: black windowtext windowtext black; background-color: transparent;" align="right"><font size="3" color="#000000" face="Calibri">222</font></td> <td style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: black windowtext windowtext black; background-color: transparent;" align="right"><font size="3" color="#000000" face="Calibri">1234</font></td> <td style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: #0563c1 windowtext windowtext #0563c1; background-color: transparent;"><a href="mailto:f@f.com"><font size="3" color="#0563c1" face="Calibri">f@f.com</font></a></td> <td style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: black windowtext windowtext black; background-color: transparent;" align="right"><font size="3" color="#000000" face="Calibri">0</font></td> <td style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: black windowtext windowtext black; background-color: transparent;"><font size="3" color="#000000" face="Calibri">17/6/2019</font></td> </tr> <tr style="height: 15pt;"> <td style="border-width: 0px 0.5pt 0.5pt; border-style: none solid solid; border-color: black windowtext windowtext; height: 15pt; background-color: transparent;" align="right" height="20"><font size="3" color="#000000" face="Calibri">5</font></td> <td style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: black windowtext windowtext black; background-color: transparent;"><font size="3" color="#000000" face="Calibri">UPDATE</font></td> <td style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: black windowtext windowtext black; background-color: transparent;" align="right"><font size="3" color="#000000" face="Calibri">222</font></td> <td style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: black windowtext windowtext black; background-color: transparent;" align="right"><font size="3" color="#000000" face="Calibri">12345</font></td> <td style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: #0563c1 windowtext windowtext #0563c1; background-color: transparent;"><a href="mailto:f@f.com"><font size="3" color="#0563c1" face="Calibri">f@f.com</font></a></td> <td style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: black windowtext windowtext black; background-color: transparent;" align="right"><font size="3" color="#000000" face="Calibri">0</font></td> <td style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: black windowtext windowtext black; background-color: transparent;"><font size="3" color="#000000" face="Calibri">17/6/2019</font></td> </tr> </tbody> </table> <p>I need the o/p as</p> <p>ADD 222 12345 <a href="mailto:f@f.com">f@f.com</a></p> <p>if any updations done for Mob &amp; Email then the updated record will be fetch into the o/p.</p> <p>&nbsp;</p> <p>Is it possible to do in Datatable querying or linq</p>https://www.aspforums.net:443/Threads/921295/Select-Distinct-latest-updated-value-in-SQL-Server/https://www.aspforums.net:443/Threads/921295/Select-Distinct-latest-updated-value-in-SQL-Server/Tue, 18 Jun 2019 01:43:11 GMTSelect Distinct latest updated value in SQL Server<p>Hi <a class="username" rel="meetsree83">meetsree83</a>,</p> <p>I have updated sample query refer below link -</p> <p><a href="https://www.aspforums.net/Threads/921295/Avoid-Duplicate-records/Replies/6#Replies">https://www.aspforums.net/Threads/921295/Avoid-Duplicate-records/Replies/6#Replies</a></p>https://www.aspforums.net:443/Threads/921295/Select-Distinct-latest-updated-value-in-SQL-Server/https://www.aspforums.net:443/Threads/921295/Select-Distinct-latest-updated-value-in-SQL-Server/Tue, 18 Jun 2019 04:41:57 GMT