Answers.Body: <p>Thanks to @carlcs for pointers managed to get this working with the following:</p>
  
  <pre><code>$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::User);
  $criteria-&gt;limit = NULL;
  
  $query = craft()-&gt;elements-&gt;buildElementsQuery($criteria);
  $params = array(
      ':interest' =&gt; '%"8948"%',
  );
  $query-&gt;andWhere("field_interests LIKE :interest", $params);
  $result = $query-&gt;queryAll() ;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-06T15:09:59.473Z
Answers.LastActivityDate: 2016-07-06T15:19:43.153Z
Answers.LastEditDate: 2016-07-06T15:19:43.153Z
Answers.UserDisplayName: Lettie
Body: <p>Hi I have a plugin which I am running an sql statement from.</p>
  
  <pre><code>$users = craft()-&gt;db-&gt;createCommand("SELECT craft_users.id as userId, craft_users.firstName, craft_users.lastName, craft_users.email FROM craft_users INNER JOIN craft_content on craft_users.id = craft_content.elementId WHERE craft_content.field_interests LIKE '%\"8948\"%'");
  </code></pre>
  
  <p>The query is not returning the expected results from the createCommand function in fact it returns an empty array. But if I run it directly in the database it works perfectly and returns the entries.</p>
  
  <p>I also tried building this with the query builder but it was throwing errors and not finding the user table.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-07-06T12:56:07.510Z
Comments.Text: Hey Lettie, not answering your question, but here’s another solution to add a `LIKE` condition to a dbCommand http://craftcms.stackexchange.com/questions/10526/get-entry-by-value-from-custom-field
Comments.UserDisplayName: carlcs
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-07-06T15:07:58.220Z
Comments.Text: @carlcs cheers managed to get this working with those pointers.
Comments.UserDisplayName: Lettie
Tags: <plugin-development><database><mysql><createcommand>
Title: createCommand sql query not working in plugin
ThreadText: # createCommand sql query not working in plugin
  
  (Asked by: username_0 on 2016-07-06)
  
  Hi I have a plugin which I am running an sql statement from.
  
  ```
  $users = craft()->db->createCommand("SELECT craft_users.id as userId, craft_users.firstName, craft_users.lastName, craft_users.email FROM craft_users INNER JOIN craft_content on craft_users.id = craft_content.elementId WHERE craft_content.field_interests LIKE '%\"8948\"%'");
  
  ```
  
  The query is not returning the expected results from the createCommand function in fact it returns an empty array. But if I run it directly in the database it works perfectly and returns the entries.
  
  I also tried building this with the query builder but it was throwing errors and not finding the user table.
  
  **Tags:** plugin-development, database, mysql, createcommand
  
  > **Comments:**
  > **username_1**: Hey username_0, not answering your question, but here’s another solution to add a `LIKE` condition to a dbCommand http://craftcms.stackexchange.com/questions/10526/get-entry-by-value-from-custom-field  
  > **username_0**: @username_1 cheers managed to get this working with those pointers.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2016-07-06. Score: 3
  
  Thanks to @username_1 for pointers managed to get this working with the following:
  
  ```
  $criteria = craft()->elements->getCriteria(ElementType::User);
  $criteria->limit = NULL;
  
  $query = craft()->elements->buildElementsQuery($criteria);
  $params = array(
      ':interest' => '%"8948"%',
  );
  $query->andWhere("field_interests LIKE :interest", $params);
  $result = $query->queryAll() ;
  
  ```
  
  
  ---
  
  