× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

SQL Select WHERE Column NOT LIKE across multiple lines

Cristian Lupașcu
Mar 31, 2015
<p>If you need to select the <code>ID_Loc</code> values for which there is no record matching the <code>'%Hello'</code> pattern, here's the query to do it:</p> <pre><code>SELECT ID_loc FROM data_full group by ID_Loc having max(case when DATA LIKE '%Hello' then 1 else 0 end) = 0; </code></pre> <p>This is the result: <a href="http://sqlfiddle.com/#!6/38130/33">http://sqlfiddle.com/#!6/38130/33</a></p> <p>If you also need to apply the <code>Type = 'RMKS'</code> filter, you can do so in a <code>WHERE</code> clause (<a href="http://sqlfiddle.com/#!6/38130/35">sqlfiddle</a>):</p> <pre><code>SELECT ID_loc FROM data_full where type = 'RMKS' group by ID_Loc having max(case when DATA LIKE '%Hello' then 1 else 0 end) = 0; </code></pre> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/29369372/SQL%20Select%20WHERE%20Column%20NOT%20LIKE%20across%20multiple%20lines/29369555">Stack Overflow</a>.</p>
comments powered by Disqus