query has no result for anonymous I have below query , when it run with non-registered user return null but with any register used with any role has result .
also non-registered user has permission to view any product 

$result = db_query("SELECT * FROM {node} node
LEFT JOIN {field_data_field_course_ref} field_data_field_course_ref ON node.nid = field_data_field_course_ref.entity_id AND (field_data_field_course_ref.entity_type = 'node' AND field_data_field_course_ref.deleted = '0')
LEFT JOIN {commerce_product} commerce_product_field_data_field_course_ref ON field_data_field_course_ref.field_course_ref_product_id = commerce_product_field_data_field_course_ref.product_id
WHERE (( (node.nid = :nid ) )AND(( (node.status = '1') AND (node.type IN  ('course_display')) )))
", array(':nid' =&gt; $nid));
      $coursePIDs = array();

      //get node product variation 

      foreach ($result as $record) {
        $coursePIDs[$record-&gt;field_course_ref_product_id] = $record-&gt;field_course_ref_product_id;
      }

 ym($coursePIDs);


any idea?
My usual answer for this is product access permissions haven't been set that would allow anonymous users to view all products, but since you're creating this query directly it isn't clear to me that that would be getting in the way. I suppose Drupal is still running query altering on this and somehow alerting the product module that it's involved?

A simple way to rule that out would be to grant anonymous users permission to view any product of any type and see i they get results. But really seeing the query actually run by Drupal would be useful.