Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To get the results described in your question the following works.</p> <pre><code>SELECT * FROM datatable WHERE refid = 11 OR refid = 16 </code></pre> <p>If you look at your required results:</p> <pre><code>id refid date1 date2 nextdate 10 11 2007-02-15 2008-02-15 002/2007 11 11 2008-02-21 2009-02-21 001/2008 12 11 2009-02-09 2010-02-09 001/2009 13 11 2010-02-09 2011-02-09 002/2010 14 11 2011-07-19 2012-07-19 054/2011 15 11 2012-07-17 2014-07-17 066/2012 25 16 2007-02-15 2008-02-15 004/2007 27 16 2009-02-10 2010-02-10 004/2009 28 16 2010-02-12 2011-02-12 005/2010 29 16 2011-07-26 2012-07-26 055/2011 30 16 2012-07-18 2014-07-18 067/2012 </code></pre> <p>You will notice that the <code>date2</code> field does not meet the criteria which you have defined in your question:</p> <blockquote> <p>I have this datatable. I need to filter datatable by following condition: Remove all rows with <code>refid</code> where <code>date2</code> is less than 2014-01-01</p> </blockquote> <p>The date2 fields range from between 2008-02-15 and 2014-07-18. The only other reference which you have stated in your criteria was "with <code>refid</code>". Looking at your table and the results required, you will notice that the <code>refid</code> of the items you wanted to select were either 11 or 16 so the filtering on date specified in the question is proving to be more of a distraction to those attempting to help. You should consider clarifying your question to prevent further confusion and maybe creating an sql fiddle (goto: <a href="http://sqlfiddle.com/" rel="nofollow">http://sqlfiddle.com/</a>) so that people have the ability to compare their results to your required results rather than telling people to re-read your question.</p> <p><strong>EDIT:</strong></p> <p>The following should return all dataTable results where there is one or more dataTable entries with the same <code>refid</code> and <code>date2 &gt; '2014-01-01'</code></p> <pre><code>SELECT * FROM datatable t1 INNER JOIN ( SELECT DISTINCT refid FROM datatable WHERE date2 &gt; '2014-01-01' )t2 ON t1.refid = t2.refid </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload