diff --git a/data/CRMEntity.php b/data/CRMEntity.php
index 2ff6a3c47640c7ccbd86a2867470917f8027d793..40240010ce00cdc875a118ee6af732e58f13bf70 100644
--- a/data/CRMEntity.php
+++ b/data/CRMEntity.php
@@ -2653,12 +2653,20 @@ class CRMEntity {
 			}
 		}
 
+                $query = "select crmid as id ";
 		$entityfields = getEntityField($module);
 		$querycolumnnames = implode(',', $lookupcolumns);
 		$entitycolumnnames = $entityfields['fieldname'];
-		$query = "select crmid as id, $querycolumnnames, $entitycolumnnames as name ";
+                $log->fatal('$entitycolumnnames');
+                $log->fatal($entitycolumnnames);
+                if(!empty($querycolumnnames)){
+                    $query .= ", $querycolumnnames";
+                }
+                if(!empty($entitycolumnnames)){
+                    $query .= ", $entitycolumnnames as name ";
+                }
 		$query .= " FROM $this->table_name ";
-		$query .=" INNER JOIN vtiger_crmentity ON $this->table_name.$this->table_index = vtiger_crmentity.crmid AND deleted = 0 ";
+		$query .= " INNER JOIN vtiger_crmentity ON $this->table_name.$this->table_index = vtiger_crmentity.crmid AND deleted = 0 ";
 
 		//remove the base table
 		$LookupTable = array_unique($lookuptables);