How do I query a content type with custom fields in the 'condition' statement I need to query a content type both returning and filtering on conditions of custom fields. 

$query = db_select('node', 'n');
$query  -&gt;fields('n',array('field_customfield1','field_customfield2'))
        -&gt;condition('type', 'myContentType')
    -&gt;condition('field_customfield3',$user-&gt;uid,'=')
    -&gt;condition('field_customfield4',$anemailaddress,'=');
$foundrecord = $query-&gt;execute();


This doesn't seem to work. My issue is I can't figure out how to reference the custom fields in queries. 

Any help GREATLY appreciated!
You'd be better off using an EntityFieldQuery for this:

$query = new EntityFieldQuery;
$query-&gt;entityCondition('entity_type', 'node')
  -&gt;entityCondition('bundle', 'myContentType')
  -&gt;propertyCondition('status', 1) // in case you need it
  -&gt;fieldCondition('field_customfield3', 'value', $user-&gt;uid)
  -&gt;fieldCondition('field_customfield4', 'value', $anemailaddress);

$results = $query-&gt;execute();

if (isset($results['node'])) {
  $nodes = node_load_multiple(array_keys($results['node']));

  foreach ($nodes as $node) {
    $customerfield1 = field_get_items('node', $node, 'field_customerfield1');
    $first_value = $customerfield1[0]['value'];

    // etc...
  }
}


Even though it's more code, and more overhead, it has advantages over going into the database tables directly.


You don't need to make the JOINs yourself
EntityFieldQuery respects node revisions, which will be harder to keep track of well using a custom query
Your code is now portable if you decide to change the storage backend for fields to something other than MySQL (MongoDB for example).