Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Initially you have to <code>UPDATE</code> all the current record with their contains value:</p> <pre><code>UPDATE UserEntry SET contains = CASE WHEN screen_name LIKE CONCAT('%', name ,'%') OR description LIKE CONCAT('%', name ,'%') THEN True ELSE False END </code></pre> <p><a href="http://sqlfiddle.com/#!2/99fbd/1/0" rel="nofollow">Demo on SQLFiddle</a></p> <p>Then to maintain the integrity of the <code>contain</code> values whenever new records are inserted or existing records are updated you will need to use <code>TRIGGER</code>s:</p> <pre><code>CREATE TRIGGER TRG_UserEntry_BeforeInsert BEFORE INSERT ON UserEntry FOR EACH ROW SET new.contains = CASE WHEN new.screen_name LIKE CONCAT('%', new.name ,'%') OR new.description LIKE CONCAT('%', new.name ,'%') THEN True ELSE False END; </code></pre> <p>And you'll need an identical one for <code>BEFORE UPDATE</code> too. </p> <p>See a <a href="http://sqlfiddle.com/#!2/1664b/1/0" rel="nofollow">working demo on SQLFiddle</a>, note that I do an <code>UPDATE</code> on the last row which is why it shows <code>contains = 1</code> too.</p> <p>Since you are using SQLite you can't use <code>CONCAT()</code> so instead use <code>'%'||new.name||'%'</code>. And since your <code>contains</code> column is of type <code>text</code> you need to use quoted strings for the <code>True</code> and <code>False</code> values e.g.</p> <pre><code>CASE WHEN new.screen_name LIKE '%'||new.name||'%' OR new.description LIKE '%'||new.name||'%' THEN "Y" ELSE "N" END; </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. 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