Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is quite basic but if I've understood you correctly:</p> <pre><code>DELETE FROM tableName WHERE date2 &lt; '2014-01-01' AND NOT (refid IS NULL) </code></pre> <p><strong>Edit</strong></p> <p>As stated in the comment below I possibly misunderstood the following part of the question to mean that the entries needed deleting.</p> <blockquote> <p>Remove all rows with refid where date2 is less than 2014-01-01</p> </blockquote> <p>In which case the following would return all results after the specified date instead:</p> <pre><code>SELECT * FROM tableName WHERE date2 &gt; '2014-01-01' AND NOT (refid IS NULL) </code></pre> <p>I have also assumed that the "with refid" means that <code>refid</code> should be populated.</p> <p>To get the results described in the original question however I'd simplify the query as follows as the date part specificied wouldn't give the results:</p> <pre><code>SELECT * FROM tableName WHERE (refid = 11) OR (refid = 16) </code></pre> <p><strong>Another Edit</strong></p> <p>The following should return all entries assigned to a <code>refid</code> with any entries with a <code>date2</code> after <code>2014-01-01</code></p> <pre><code>SELECT DISTINCT t1.* FROM tableName t1 INNER JOIN tableName t2 ON t1.refid = t2.refid AND t2.date2 &gt; '2014-01-01' </code></pre> <p>Alternatively you could use exists:</p> <pre><code>SELECT * FROM tableName t1 WHERE EXISTS( SELECT * FROM tableName t2 WHERE t1.refid = t2.refid AND t2.date2 &gt; '2014-01-01' ) </code></pre> <p>Or link to a separate table of <code>refid</code>'s which fit the profile</p> <pre><code>SELECT * FROM tableName t1 INNER JOIN ( SELECT DISTINCT refid FROM tableName 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.
    3. 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