<?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: Remove Duplicate Entries from SQLQuery Based on Date in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Remove-Duplicate-Entries-from-SQLQuery-Based-on-Date/m-p/821816#M100100</link>
    <description>&lt;P&gt;Which error are you getting?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;They should go inside Custom SQL() part (I tried it and it did work just fine with the t2."wt%")&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;	CustomSQL(
		"\[SELECT 
			t1.Cylinder, 
			t1.Batch, 
			t1."Batch Date", 
			t2."Received Date",
			t2.Supplier, 
			t2.Lot,
			t2."wt%"
		FROM t1
			LEFT OUTER JOIN t2 ON 
				t1.Cylinder = t2.Cylinder
				AND t1."Batch Date" &amp;gt;= t2."Received Date"

	]\")&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want all columns from t2, I think the SQL JMP is using supports t2.*&lt;/P&gt;</description>
    <pubDate>Tue, 10 Dec 2024 20:52:45 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2024-12-10T20:52:45Z</dc:date>
    <item>
      <title>Remove Duplicate Entries from SQLQuery Based on Date</title>
      <link>https://community.jmp.com/t5/Discussions/Remove-Duplicate-Entries-from-SQLQuery-Based-on-Date/m-p/820268#M99875</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried to use this video linked below to use the SQLQuery function. However, I'm having an issue.&lt;/P&gt;&lt;P&gt;community.jmp.com/t5/video/gallerypage/video-id/tvcW9lZTE6Ie3IFXxeru0AYNqvj5AB5r&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Problem: Take Table 2 with "cylinder" "Received_Date" and "lot" &amp;amp; merge that into Table 1 that has "batch", "cylinder" and "Batch_Date"&lt;/P&gt;&lt;P&gt;I need to match exactly on "Cylinder" and then take the nearest backward "Received Date" to the "Batch Date" (Batch_Date &amp;gt;= Received_Date).&lt;/P&gt;&lt;P&gt;I created the query &amp;amp; also did the step to create a numeric tag that should theoretically provide only 1 unique lot number for each batch (not shown in table below)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, this is what I'm getting&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Batch&lt;/TD&gt;&lt;TD&gt;Batch Date&lt;/TD&gt;&lt;TD&gt;Cylinder Number&lt;/TD&gt;&lt;TD&gt;Lot Number&lt;/TD&gt;&lt;TD&gt;Received Date&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2/13/2023&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;55&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;6/14/2022&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2/13/2023&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;55&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;10/21/2022&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2/13/2023&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;55&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;11/30/2022&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There should only be 1 row populated from the query (should be the last row 11/30/2022); the other ones are "ghosts" as we only made 1 "Batch 1"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help on how to improve the SQL code to prevent duplicate entries &amp;amp; pick the entry only if the received date is the closest &amp;lt;= batch date?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This was the code from the SQLQuery interface that was given&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SELECT DISTINCT t1.Batch, t1.Batch_Date AS Date, t1.Cylinder_Number,&lt;BR /&gt;t2.Lot_Number, t2.Cylinder_Number AS "Cylinder_Number 2", t2.Lot_Date AS "Date 2", MIN(t2."Batch Num") AS "Minimum-Batch Num"&lt;BR /&gt;FROM "Table 1" t1&lt;BR /&gt;LEFT OUTER JOIN "Table 2" t2&lt;BR /&gt;ON ( ( t1.Cylinder_Number = t2.Cylinder_Number ) AND ( t1.Cat_Date &amp;gt;= t2.Lot_Date ) )&lt;BR /&gt;GROUP BY t1.Batch, t1.Batch_Date, t1.Cylinder_Number,&amp;nbsp;&lt;BR /&gt;t2.Lot_Number, t2.Cylinder_Number, t2.Lot_Date;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2024 02:17:10 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Remove-Duplicate-Entries-from-SQLQuery-Based-on-Date/m-p/820268#M99875</guid>
      <dc:creator>Polygon0516</dc:creator>
      <dc:date>2024-12-03T02:17:10Z</dc:date>
    </item>
    <item>
      <title>Re: Remove Duplicate Entries from SQLQuery Based on Date</title>
      <link>https://community.jmp.com/t5/Discussions/Remove-Duplicate-Entries-from-SQLQuery-Based-on-Date/m-p/820325#M99880</link>
      <description>&lt;P&gt;Are these JMP tables you are performing the SQL query to? Can you share the tables?&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2024 11:57:30 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Remove-Duplicate-Entries-from-SQLQuery-Based-on-Date/m-p/820325#M99880</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-12-03T11:57:30Z</dc:date>
    </item>
    <item>
      <title>Re: Remove Duplicate Entries from SQLQuery Based on Date</title>
      <link>https://community.jmp.com/t5/Discussions/Remove-Duplicate-Entries-from-SQLQuery-Based-on-Date/m-p/820360#M99890</link>
      <description>&lt;P&gt;Here are the files - sorry, meant to attach these.&lt;/P&gt;&lt;P&gt;Table 1-1 and Table 2-2 are as described above.&lt;/P&gt;&lt;P&gt;Query Results shows the final table where there are multiple entries for each batch (but there should only be 1 entry per batch as described above).&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2024 15:03:04 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Remove-Duplicate-Entries-from-SQLQuery-Based-on-Date/m-p/820360#M99890</guid>
      <dc:creator>Polygon0516</dc:creator>
      <dc:date>2024-12-03T15:03:04Z</dc:date>
    </item>
    <item>
      <title>Re: Remove Duplicate Entries from SQLQuery Based on Date</title>
      <link>https://community.jmp.com/t5/Discussions/Remove-Duplicate-Entries-from-SQLQuery-Based-on-Date/m-p/820361#M99891</link>
      <description>&lt;P&gt;Just replied to the main thread with the files, thanks for reaching out&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2024 15:03:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Remove-Duplicate-Entries-from-SQLQuery-Based-on-Date/m-p/820361#M99891</guid>
      <dc:creator>Polygon0516</dc:creator>
      <dc:date>2024-12-03T15:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: Remove Duplicate Entries from SQLQuery Based on Date</title>
      <link>https://community.jmp.com/t5/Discussions/Remove-Duplicate-Entries-from-SQLQuery-Based-on-Date/m-p/820418#M99900</link>
      <description>&lt;P&gt;This is quite close to the limit on what I would attempt to do with JMP's limited SQL capabilities (at least when using data tables). It is most likely simpler to use SQL + JSL&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

res = New SQL Query(
	Version(130),
	Connection("JMP"),
	JMP Tables(
		["t1" =&amp;gt; "$DOWNLOADS\Table1-1.jmp",
		"t2" =&amp;gt; "$DOWNLOADS\Table 2-2.jmp"]
	),
	QueryName("SQLQuery2"),
	CustomSQL(
		"\[SELECT 
			t1.Cylinder, 
			t1.Batch, 
			t1."Batch Date", 
			t2."Received Date",
			t2.Supplier, 
			t2.Lot
		FROM t1
			LEFT OUTER JOIN t2 ON 
				t1.Cylinder = t2.Cylinder
				AND t1."Batch Date" &amp;gt;= t2."Received Date"

	]\")
) &amp;lt;&amp;lt; Run;


res &amp;lt;&amp;lt; select where(Row() == Col Max(Row(), :Cylinder, :Batch) | Is Missing(:Lot));
res &amp;lt;&amp;lt; Invert Row Selection;
res &amp;lt;&amp;lt; delete rows;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Dec 2024 17:35:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Remove-Duplicate-Entries-from-SQLQuery-Based-on-Date/m-p/820418#M99900</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-12-03T17:35:37Z</dc:date>
    </item>
    <item>
      <title>Re: Remove Duplicate Entries from SQLQuery Based on Date</title>
      <link>https://community.jmp.com/t5/Discussions/Remove-Duplicate-Entries-from-SQLQuery-Based-on-Date/m-p/820629#M99933</link>
      <description>&lt;P&gt;Hello - thank you for the quick help! I tried the macro &amp;amp; unfortunately for some items it is keeping the oldest possible date. It doesn't appear to be doing this for all entries though ( see last row of the table below).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So this is a definite improvement that there aren't multiple rows for the same batch, but it's not consistently pulling the right lot/received date for that batch in question.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;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wed, 04 Dec 2024 15:01:39 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Remove-Duplicate-Entries-from-SQLQuery-Based-on-Date/m-p/820629#M99933</guid>
      <dc:creator>Polygon0516</dc:creator>
      <dc:date>2024-12-04T15:01:39Z</dc:date>
    </item>
    <item>
      <title>Re: Remove Duplicate Entries from SQLQuery Based on Date</title>
      <link>https://community.jmp.com/t5/Discussions/Remove-Duplicate-Entries-from-SQLQuery-Based-on-Date/m-p/820662#M99940</link>
      <description>&lt;P&gt;I'm not really sure how to read your table. If I take a look at Table 2-2 there is only 1 row for Cylinder 1 which has Received date 05/20/2022&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1733329094365.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/70845iD66437165D88E5DE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1733329094365.png" alt="jthi_0-1733329094365.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2024 16:18:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Remove-Duplicate-Entries-from-SQLQuery-Based-on-Date/m-p/820662#M99940</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-12-04T16:18:35Z</dc:date>
    </item>
    <item>
      <title>Re: Remove Duplicate Entries from SQLQuery Based on Date</title>
      <link>https://community.jmp.com/t5/Discussions/Remove-Duplicate-Entries-from-SQLQuery-Based-on-Date/m-p/820972#M99996</link>
      <description>&lt;P&gt;Hi - replying to keep the topic active. I think something occurred when I updated my file to remove proprietary information. I will look at it more tomorrow &amp;amp; will get back to you with a reply.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2024 02:34:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Remove-Duplicate-Entries-from-SQLQuery-Based-on-Date/m-p/820972#M99996</guid>
      <dc:creator>Polygon0516</dc:creator>
      <dc:date>2024-12-06T02:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: Remove Duplicate Entries from SQLQuery Based on Date</title>
      <link>https://community.jmp.com/t5/Discussions/Remove-Duplicate-Entries-from-SQLQuery-Based-on-Date/m-p/821796#M100094</link>
      <description>Thank you for this assistance! I realized there was an error within my original data set (I modified it for entry on this website to anonymize the data). This code has been working well, will reach out with any other questions.</description>
      <pubDate>Tue, 10 Dec 2024 18:49:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Remove-Duplicate-Entries-from-SQLQuery-Based-on-Date/m-p/821796#M100094</guid>
      <dc:creator>Polygon0516</dc:creator>
      <dc:date>2024-12-10T18:49:09Z</dc:date>
    </item>
    <item>
      <title>Re: Remove Duplicate Entries from SQLQuery Based on Date</title>
      <link>https://community.jmp.com/t5/Discussions/Remove-Duplicate-Entries-from-SQLQuery-Based-on-Date/m-p/821797#M100095</link>
      <description>&lt;P&gt;One last question - how can I add where more columns are pulled over from Table 2 into the final query table, even if I'm not using them as a match criteria?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried adding into your code above a t2."wt%" column but the code now throws me an error. I have other columns I'd like to pull in at the same time (about 10 columns in total) but not sure how to do this without getting an error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 18:55:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Remove-Duplicate-Entries-from-SQLQuery-Based-on-Date/m-p/821797#M100095</guid>
      <dc:creator>Polygon0516</dc:creator>
      <dc:date>2024-12-10T18:55:27Z</dc:date>
    </item>
    <item>
      <title>Re: Remove Duplicate Entries from SQLQuery Based on Date</title>
      <link>https://community.jmp.com/t5/Discussions/Remove-Duplicate-Entries-from-SQLQuery-Based-on-Date/m-p/821816#M100100</link>
      <description>&lt;P&gt;Which error are you getting?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;They should go inside Custom SQL() part (I tried it and it did work just fine with the t2."wt%")&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;	CustomSQL(
		"\[SELECT 
			t1.Cylinder, 
			t1.Batch, 
			t1."Batch Date", 
			t2."Received Date",
			t2.Supplier, 
			t2.Lot,
			t2."wt%"
		FROM t1
			LEFT OUTER JOIN t2 ON 
				t1.Cylinder = t2.Cylinder
				AND t1."Batch Date" &amp;gt;= t2."Received Date"

	]\")&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want all columns from t2, I think the SQL JMP is using supports t2.*&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 20:52:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Remove-Duplicate-Entries-from-SQLQuery-Based-on-Date/m-p/821816#M100100</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-12-10T20:52:45Z</dc:date>
    </item>
  </channel>
</rss>

