<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Query Builder - Unique Records in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17970#M16383</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;DISTINCT won't help the OP, because there really aren't any distinct rows here.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I found a query that would solve the second case.&amp;nbsp; I added 6 rows at the bottom that duplicate the max times for each asset, plus added an X variable.&amp;nbsp; Here is the table:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="11335_parts1_duptimes.png" style="width: 813px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/2950i4EDB1271EF954F76/image-size/medium?v=v2&amp;amp;px=400" role="button" title="11335_parts1_duptimes.png" alt="11335_parts1_duptimes.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And here is the query that works (it requires one subquery and one subquery within a subquery)):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="11336_parts2_duptimes_query.png" style="width: 1092px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/2951iBF0D321BB3B2F1A6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="11336_parts2_duptimes_query.png" alt="11336_parts2_duptimes_query.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The custom expression is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: 'courier new', courier;"&gt;t1.Time = (SELECT MAX(tInner.Time) FROM parts tInner WHERE t1.Asset = tInner.Asset) &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: 'courier new', courier;"&gt;AND&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: 'courier new', courier;"&gt;t1.X = (SELECT MAX(tInner.X) FROM parts tInner WHERE t1.Asset = tInner.Asset AND &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; tInner.Time = (SELECT MAX(tInner2.Time) FROM parts tInner2 WHERE tInner.Asset = tInner2.Asset))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I capitalized all the SQL keywords to make it easier to read.&amp;nbsp; I tried some simpler queries, but they did not work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HTH,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Eric&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 19 Oct 2016 02:24:00 GMT</pubDate>
    <dc:creator>Eric_Hill</dc:creator>
    <dc:date>2016-10-19T02:24:00Z</dc:date>
    <item>
      <title>Query Builder - Unique Records</title>
      <link>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17960#M16373</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;Hello , &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;After quite a bit of personal struggle to solve my problem, I've decided to post it as a question to user and JMP community. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; line-height: 1.5em;"&gt;Have a database from which p1, p2, asset and time are pulled from. Database is an accumulating database which means parameters p1, and p2 are loaded as representing the last state for each &lt;/SPAN&gt;&lt;STRONG style="font-size: 12pt; line-height: 1.5em;"&gt;asset&lt;/STRONG&gt;&lt;SPAN style="font-size: 12pt; line-height: 1.5em;"&gt; at a specific &lt;/SPAN&gt;&lt;STRONG style="font-size: 12pt; line-height: 1.5em;"&gt;time&lt;/STRONG&gt;&lt;SPAN style="font-size: 12pt; line-height: 1.5em;"&gt;. In other words, prior older instances of p1 and p2 are invalid, and the most recent versions of p1 and p2 are needed for a given &lt;/SPAN&gt;&lt;STRONG style="font-size: 12pt; line-height: 1.5em;"&gt;asset&lt;/STRONG&gt;&lt;SPAN style="font-size: 12pt; line-height: 1.5em;"&gt; at the latest reported &lt;/SPAN&gt;&lt;STRONG style="font-size: 12pt; line-height: 1.5em;"&gt;time&lt;/STRONG&gt;&lt;SPAN style="font-size: 12pt; line-height: 1.5em;"&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;Hence, what&amp;nbsp; I need is an descending order via &lt;STRONG&gt;time&lt;/STRONG&gt; and then force the outcome to be unique at &lt;STRONG&gt;asset&lt;/STRONG&gt; level. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;Any ideas of how I need to direct this in query builder ? &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;I rather prefer to have a solution by not using a custom SQL.... I actually have a solution at Custom SQL but I like to learn how to do this within query builder as I will be adding a few more pieces which be hard to do in the Custom SQL&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;Appreciate the help. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;Altug Bayram&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Apr 2016 20:58:55 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17960#M16373</guid>
      <dc:creator>altug_bayram</dc:creator>
      <dc:date>2016-04-11T20:58:55Z</dc:date>
    </item>
    <item>
      <title>Re: Query Builder - Unique Records</title>
      <link>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17961#M16374</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Altug,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please see the image below for getting a descending order for time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Right click on your time variable in Available Columns and select "Order By"&amp;nbsp; a new dialogue box will pop up in the lower right.&amp;nbsp; From there you can pick the descending arrow to get the desired time order.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could then use a filter with a prompt to select a unique asset level.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="11330_pastedImage_0.png" style="width: 1318px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/2946i0E4C65D9DA9B7F1C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="11330_pastedImage_0.png" alt="11330_pastedImage_0.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Oct 2016 02:23:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17961#M16374</guid>
      <dc:creator>Bill_Worley</dc:creator>
      <dc:date>2016-10-19T02:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: Query Builder - Unique Records</title>
      <link>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17962#M16375</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Bill&lt;/P&gt;&lt;P&gt;Thanks for quick reply. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, unless I am missing a critical thing here, this does not solve my problem.&lt;/P&gt;&lt;P&gt;1) Any asset's last valid point are typically not at the same time point, they are quite different. They can have years of difference.&amp;nbsp; &lt;/P&gt;&lt;P&gt;2) I am not looking for a prompt solution if possible. I need this to be fully automated. &lt;/P&gt;&lt;P&gt;3) I am really not sure how "Filter By" with &amp;gt;= can make it unique either. I think you rather meant to filter by "="&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I need an approach that picks up the latest chronological entry for any asset without having to specify a time filter (cause the latest data can be anywhere in time). &lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Apr 2016 13:36:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17962#M16375</guid>
      <dc:creator>altug_bayram</dc:creator>
      <dc:date>2016-04-12T13:36:52Z</dc:date>
    </item>
    <item>
      <title>Re: Query Builder - Unique Records</title>
      <link>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17963#M16376</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey, altug,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is a table that I believe resembles what you are describing (but assume it is in a database rather than JMP):&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="11331_parts_table.png" style="width: 702px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/2947iB9B2E51E72128A0C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="11331_parts_table.png" alt="11331_parts_table.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;My understand is that you would like to retrieve one row for A1, A2, A3, and A4 for which Time is the maximum.&amp;nbsp; Is that correct?&amp;nbsp; &lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;I do not believe that is possible without doing a subquery that uses the MAX function, which you can do using a Custom Expression filter.&amp;nbsp; Here is the query I ended up with:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="11332_parts_query.png" style="width: 1035px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/2948iE53E896DD732A9DF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="11332_parts_query.png" alt="11332_parts_query.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;In case that is too small to read, the custom expression is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt; font-family: 'courier new', courier;"&gt;t1.Time = (select MAX(Time) from parts t2 where t1.Asset = t2.Asset)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So you pass in the value of Asset from the main query (t1.Asset) and select rows that have the maximum Time value for that asset.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let me know if that helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Eric&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Oct 2016 02:23:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17963#M16376</guid>
      <dc:creator>Eric_Hill</dc:creator>
      <dc:date>2016-10-19T02:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: Query Builder - Unique Records</title>
      <link>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17964#M16377</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Eric, &lt;/P&gt;&lt;P&gt;First thanks for your help .... &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your understanding is correct. I am just trying to pull a single row for each asset where Time is max (or most recent).&lt;/P&gt;&lt;P&gt;I applied your formulae. However, it is giving me an error.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I applied it as the real table name first and then as "t1"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; t1.calendar_month = (select MAX(calendar_month) from my_table t2 where t1.engine_serial_num = t2.engine_serial_num)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; t1.calendar_month = (select MAX(calendar_month) from t1 t2 where t1.engine_serial_num = t2.engine_serial_num)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ERROR : relation "my_table" does not exist.&lt;/P&gt;&lt;P&gt;ERROR while executing the query [ SQLSTATE: 42P01 ]&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Apr 2016 14:48:11 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17964#M16377</guid>
      <dc:creator>altug_bayram</dc:creator>
      <dc:date>2016-04-12T14:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: Query Builder - Unique Records</title>
      <link>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17965#M16378</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey, altug,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What database are you using?&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Would you be willing to share the SQL from your Custom SQL query that gives you the result you are looking for?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Eric&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Apr 2016 14:53:57 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17965#M16378</guid>
      <dc:creator>Eric_Hill</dc:creator>
      <dc:date>2016-04-12T14:53:57Z</dc:date>
    </item>
    <item>
      <title>Re: Query Builder - Unique Records</title>
      <link>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17966#M16379</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My original example was for SQL Server, which is a little more forgiving.&amp;nbsp; For Oracle, I had to format the table name in the subquery as schema.table, plus I had to quote my mixed case names:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt; font-family: 'courier new', courier;"&gt;t1."Time" = (select MAX(t2."Time") from &lt;SPAN style="color: #ff6600;"&gt;SQBTEST.&lt;/SPAN&gt;"parts" t2 where t2."Asset" = t1."Asset")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try changing &lt;STRONG&gt;​my_table&lt;/STRONG&gt;​ in your first attempt to &lt;STRONG&gt;​&amp;lt;schema&amp;gt;.my_table&lt;/STRONG&gt;​ and see if that helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Eric&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Apr 2016 16:47:39 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17966#M16379</guid>
      <dc:creator>Eric_Hill</dc:creator>
      <dc:date>2016-04-12T16:47:39Z</dc:date>
    </item>
    <item>
      <title>Re: Query Builder - Unique Records</title>
      <link>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17967#M16380</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Eric,&lt;/P&gt;&lt;P&gt;Thanks a lot ....&lt;/P&gt;&lt;P&gt;Sorry, I took some time to figure it out w/ another query skilled person at GE. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your solution (first one) definitely worked !!! I haven't tried the second one yet. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I do have one more issue - &lt;/P&gt;&lt;P&gt;it turns out folks who populate the database inserted duplicate entry for a few assets at the same last chronological time.. So to get around it, I have another column titled say X . Manually I would simply choose the two w/ the largest X. I did not want to convert from Max(Time) to Max(X) since X by itself may not be that reliable but would be the selection factor for duplicate Time entries.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We tried converting your original custom expression to sort of including a second MAX (on X) ... but that did not work... &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So .. trying to pull each Asset where Time is MAX and if multiple entries selecting the entry w/ Max(X)&lt;/P&gt;&lt;P&gt;Any suggestions &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Apr 2016 17:59:31 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17967#M16380</guid>
      <dc:creator>altug_bayram</dc:creator>
      <dc:date>2016-04-12T17:59:31Z</dc:date>
    </item>
    <item>
      <title>Re: Query Builder - Unique Records</title>
      <link>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17968#M16381</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I forgot to add ...&lt;/P&gt;&lt;P&gt;The reason I couldn't make your query work originally is that I was not referring to the database in the correct manner. Once we did that, it worked&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Apr 2016 18:00:48 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17968#M16381</guid>
      <dc:creator>altug_bayram</dc:creator>
      <dc:date>2016-04-12T18:00:48Z</dc:date>
    </item>
    <item>
      <title>Re: Query Builder - Unique Records</title>
      <link>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17969#M16382</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If it's a duplicate entry perhaps using the DISTINCT keyword will help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Apr 2016 18:28:47 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17969#M16382</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2016-04-12T18:28:47Z</dc:date>
    </item>
    <item>
      <title>Re: Query Builder - Unique Records</title>
      <link>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17970#M16383</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;DISTINCT won't help the OP, because there really aren't any distinct rows here.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I found a query that would solve the second case.&amp;nbsp; I added 6 rows at the bottom that duplicate the max times for each asset, plus added an X variable.&amp;nbsp; Here is the table:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="11335_parts1_duptimes.png" style="width: 813px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/2950i4EDB1271EF954F76/image-size/medium?v=v2&amp;amp;px=400" role="button" title="11335_parts1_duptimes.png" alt="11335_parts1_duptimes.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And here is the query that works (it requires one subquery and one subquery within a subquery)):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="11336_parts2_duptimes_query.png" style="width: 1092px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/2951iBF0D321BB3B2F1A6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="11336_parts2_duptimes_query.png" alt="11336_parts2_duptimes_query.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The custom expression is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: 'courier new', courier;"&gt;t1.Time = (SELECT MAX(tInner.Time) FROM parts tInner WHERE t1.Asset = tInner.Asset) &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: 'courier new', courier;"&gt;AND&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: 'courier new', courier;"&gt;t1.X = (SELECT MAX(tInner.X) FROM parts tInner WHERE t1.Asset = tInner.Asset AND &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; tInner.Time = (SELECT MAX(tInner2.Time) FROM parts tInner2 WHERE tInner.Asset = tInner2.Asset))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I capitalized all the SQL keywords to make it easier to read.&amp;nbsp; I tried some simpler queries, but they did not work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HTH,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Eric&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Oct 2016 02:24:00 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17970#M16383</guid>
      <dc:creator>Eric_Hill</dc:creator>
      <dc:date>2016-10-19T02:24:00Z</dc:date>
    </item>
    <item>
      <title>Re: Query Builder - Unique Records</title>
      <link>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17971#M16384</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Eric, &lt;/P&gt;&lt;P&gt;It worked like a charm &lt;SPAN __jive_emoticon_name="happy" __jive_macro_name="emoticon" class="jive_macro_emoticon jive_emote jive_macro" src="https://community.jmp.com/7.0.4.3b79b96/images/emoticons/happy.png"&gt;&lt;/SPAN&gt; ... &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am wondering though ... would it have also worked by running the first original version of custom epxression (with only Time) AND while choosing X aggregation as "Maximum" inside "Included Columns" field ... ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks so much .... &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Apr 2016 19:17:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17971#M16384</guid>
      <dc:creator>altug_bayram</dc:creator>
      <dc:date>2016-04-12T19:17:50Z</dc:date>
    </item>
    <item>
      <title>Re: Query Builder - Unique Records</title>
      <link>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17972#M16385</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Running the original version with only Time and using the MAX aggregation on X can be made to return the correct rows, but you will not be able to find out the values of p1 and p2 for those rows.&amp;nbsp; If I do what you said leaving p1 and p2 in the query I get all the rows with the duplicate max times, because p1 and p2 become GROUP BY's for the query:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="11337_query_max_x.png" style="width: 1073px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/2952i96CAC24D35C1A656/image-size/medium?v=v2&amp;amp;px=400" role="button" title="11337_query_max_x.png" alt="11337_query_max_x.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Now, if I take p1 and p2 out of the query, the query returns the correct rows:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="11338_query_max_x_no_ps.png" style="width: 1074px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/2953i42E70B25C9702263/image-size/medium?v=v2&amp;amp;px=400" role="button" title="11338_query_max_x_no_ps.png" alt="11338_query_max_x_no_ps.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;but the whole point was to find the values of p1 and p2 for those rows, and they are gone.&amp;nbsp; So I think the double subquery approach is the only approach that answers the question you asked.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Eric&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Oct 2016 02:24:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17972#M16385</guid>
      <dc:creator>Eric_Hill</dc:creator>
      <dc:date>2016-10-19T02:24:15Z</dc:date>
    </item>
    <item>
      <title>Re: Query Builder - Unique Records</title>
      <link>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17973#M16386</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Eric,&lt;/P&gt;&lt;P&gt;I understand better now and agree w/ you . Again , thanks for the effort you provided to this issue. &lt;/P&gt;&lt;P&gt;Your help has been very valuable.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Apr 2016 19:37:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17973#M16386</guid>
      <dc:creator>altug_bayram</dc:creator>
      <dc:date>2016-04-12T19:37:59Z</dc:date>
    </item>
    <item>
      <title>Re: Query Builder - Unique Records</title>
      <link>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17974#M16387</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My pleasure.&amp;nbsp; This thread really pushed my understanding of subqueries.&amp;nbsp; I learned a lot.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Take care,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Eric&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Apr 2016 01:20:38 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/17974#M16387</guid>
      <dc:creator>Eric_Hill</dc:creator>
      <dc:date>2016-04-13T01:20:38Z</dc:date>
    </item>
    <item>
      <title>Re: Query Builder - Unique Records</title>
      <link>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/230447#M45700</link>
      <description>&lt;P&gt;This is an old post, but here goes:&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/1519"&gt;@altug_bayram&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;I forgot to add ...&lt;/P&gt;&lt;P&gt;The reason I couldn't make your query work originally is that I was not referring to the database in the correct manner. Once we did that, it worked&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;&amp;nbsp;What was the correct manner? I also get an error that says "ERROR: relation "databases_enzyme_db" does not exist; Error while preparing parameters [SQLSTATE=42P01]" and I am unsure how to trouble shoot it&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Oct 2019 21:19:56 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Query-Builder-Unique-Records/m-p/230447#M45700</guid>
      <dc:creator>JPKO</dc:creator>
      <dc:date>2019-10-23T21:19:56Z</dc:date>
    </item>
  </channel>
</rss>

