db_query and condition in custom field on my website, i have articles. All of them have custom field named event date. I want to select 50 nodes of type article with event date value "2016-07-29 16:25:00". How to do this?

I tried following code, but it looks like query cannot find any custom field column.

$nids = db_select('node', 'n')
-&gt;fields('n', array('nid'))
-&gt;fields('n', array('type'))
-&gt;fields('n', array('field_event_date'))
-&gt;condition('n.type', 'article')
-&gt;condition('n.field_event_date', "2016-07-29 16:25:00")
-&gt;range(0, 50)
-&gt;execute()
-&gt;fetchCol();
You cannot find any custom fields because fields created using the field API are not stored in the node table, but in a different table. In code, you should use the EntityFieldQuery class.

  $query = new EntityFieldQuery();
  $entities = $query-&gt;entityCondition('entity_type', 'node')
    -&gt;entityCondition('bundle', 'article')
    -&gt;propertyCondition('status', 1)
    -&gt;fieldCondition('field_event_date', 'value', '2016-07-29 16:25:00')
    -&gt;fieldOrderBy('field_event_date', 'value', 'ASC')
                    -&gt;execute();

  $nodes = node_load_multiple(array_keys($entities['node']));