<?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: Joining two tables based on dates in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Joining-two-tables-based-on-dates/m-p/462999#M70767</link>
    <description>&lt;P&gt;I think it will be easiest to Query for this and write some SQL for the join&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
// Using aliases, performing a join
dtSAT = Open("$SAMPLE_DATA/SATByYear.jmp", Invisible);
dtUS = Open("$SAMPLE_DATA/US Demographics.jmp", Invisible);
Query(
	Table(dtSAT, "t1"),
	Table(dtUS, "t2"), 

	"\[SELECT t1.State, t1."SAT Math", t2."College Degrees",
            t2."Eighth Grade Math"
       FROM t1
       LEFT OUTER JOIN t2
           ON t1.State = t2.State
       WHERE t1.'SAT Math' &amp;gt; 550;
      ]\"
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It isn't the only option but it should be fairly simple and easy to understand (if you know SQL).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&lt;/P&gt;
&lt;P&gt;Depending on your table size, you could also perform left join (or full join) and then remove values which do not pass the date check:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt1 = New Table("Untitled",
	Add Rows(6),
	New Column("Column 1", Character, "Nominal", Set Values({"a", "a", "a", "b", "b", "b"})),
	New Column("date", Numeric, "Continuous", Format("Best", 12), Set Values([2, 3, 4, 2, 3, 5]))
);

dt2 = New Table("Untitled 2",
	Add Rows(2),
	New Column("Column 1", Character, "Nominal", Set Values({"a", "b"})),
	New Column("start", Numeric, "Continuous", Format("Best", 12), Set Values([1, 1])),
	New Column("end", Numeric, "Continuous", Format("Best", 12), Set Selected, Set Values([3, 6]))
);

dt3 = dt1 &amp;lt;&amp;lt; Join(
	With(dt2),
	By Matching Columns(:Column 1 = :Column 1),
	Drop multiples(0, 0),
	Include Nonmatches(1, 0),
	Preserve main table order(1)
);

dt3 &amp;lt;&amp;lt; New Column("OK", Numeric, Nominal, &amp;lt;&amp;lt; Set Each Value(:start &amp;lt; :date &amp;lt; :end));
dt3 &amp;lt;&amp;lt; Select Where(:OK == 0);// &amp;lt;&amp;lt; Delete Rows;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 22 Feb 2022 17:14:28 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2022-02-22T17:14:28Z</dc:date>
    <item>
      <title>Joining two tables based on dates</title>
      <link>https://community.jmp.com/t5/Discussions/Joining-two-tables-based-on-dates/m-p/462971#M70766</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I want to accomplish something which I think is very simple: Joining tables based on dates.&lt;/P&gt;&lt;P&gt;Let's say I have the following tables:&lt;/P&gt;&lt;P&gt;Table1 - which has the following columns: Group1, event_date.&lt;/P&gt;&lt;P&gt;Table2 - which has the following columns: Group2, start_date, end_date.&lt;/P&gt;&lt;P&gt;I want the join to work as follows: (Group1 == Group2) AND (start_date &amp;lt; date &amp;lt; end_date)&lt;/P&gt;&lt;P&gt;How can I accomplish this using a JSL code?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:44:31 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Joining-two-tables-based-on-dates/m-p/462971#M70766</guid>
      <dc:creator>Yotam</dc:creator>
      <dc:date>2023-06-10T23:44:31Z</dc:date>
    </item>
    <item>
      <title>Re: Joining two tables based on dates</title>
      <link>https://community.jmp.com/t5/Discussions/Joining-two-tables-based-on-dates/m-p/462999#M70767</link>
      <description>&lt;P&gt;I think it will be easiest to Query for this and write some SQL for the join&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
// Using aliases, performing a join
dtSAT = Open("$SAMPLE_DATA/SATByYear.jmp", Invisible);
dtUS = Open("$SAMPLE_DATA/US Demographics.jmp", Invisible);
Query(
	Table(dtSAT, "t1"),
	Table(dtUS, "t2"), 

	"\[SELECT t1.State, t1."SAT Math", t2."College Degrees",
            t2."Eighth Grade Math"
       FROM t1
       LEFT OUTER JOIN t2
           ON t1.State = t2.State
       WHERE t1.'SAT Math' &amp;gt; 550;
      ]\"
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It isn't the only option but it should be fairly simple and easy to understand (if you know SQL).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&lt;/P&gt;
&lt;P&gt;Depending on your table size, you could also perform left join (or full join) and then remove values which do not pass the date check:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt1 = New Table("Untitled",
	Add Rows(6),
	New Column("Column 1", Character, "Nominal", Set Values({"a", "a", "a", "b", "b", "b"})),
	New Column("date", Numeric, "Continuous", Format("Best", 12), Set Values([2, 3, 4, 2, 3, 5]))
);

dt2 = New Table("Untitled 2",
	Add Rows(2),
	New Column("Column 1", Character, "Nominal", Set Values({"a", "b"})),
	New Column("start", Numeric, "Continuous", Format("Best", 12), Set Values([1, 1])),
	New Column("end", Numeric, "Continuous", Format("Best", 12), Set Selected, Set Values([3, 6]))
);

dt3 = dt1 &amp;lt;&amp;lt; Join(
	With(dt2),
	By Matching Columns(:Column 1 = :Column 1),
	Drop multiples(0, 0),
	Include Nonmatches(1, 0),
	Preserve main table order(1)
);

dt3 &amp;lt;&amp;lt; New Column("OK", Numeric, Nominal, &amp;lt;&amp;lt; Set Each Value(:start &amp;lt; :date &amp;lt; :end));
dt3 &amp;lt;&amp;lt; Select Where(:OK == 0);// &amp;lt;&amp;lt; Delete Rows;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Feb 2022 17:14:28 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Joining-two-tables-based-on-dates/m-p/462999#M70767</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-02-22T17:14:28Z</dc:date>
    </item>
    <item>
      <title>Re: Joining two tables based on dates</title>
      <link>https://community.jmp.com/t5/Discussions/Joining-two-tables-based-on-dates/m-p/463065#M70772</link>
      <description>&lt;P&gt;Perfect! I didn't know you can work with SQL syntax within JMP. This will make my life a lot easier from now on.&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 22 Feb 2022 19:47:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Joining-two-tables-based-on-dates/m-p/463065#M70772</guid>
      <dc:creator>Yotam</dc:creator>
      <dc:date>2022-02-22T19:47:35Z</dc:date>
    </item>
    <item>
      <title>Re: Joining two tables based on dates</title>
      <link>https://community.jmp.com/t5/Discussions/Joining-two-tables-based-on-dates/m-p/463076#M70774</link>
      <description>&lt;P&gt;This help article might be helpful when using SQL in JMP Queries: &lt;A href="https://www.jmp.com/support/help/en/16.2/index.shtml#page/jmp/sql-functions-available-for-jmp-queries.shtml" target="_blank" rel="noopener"&gt;SQL Functions Available for JMP Queries&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Feb 2022 20:05:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Joining-two-tables-based-on-dates/m-p/463076#M70774</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-02-22T20:05:18Z</dc:date>
    </item>
  </channel>
</rss>

