I have the below query for FAQ search module modified that works in Drupal 7, which searches in two tables: 1) title 2) body but don\'t manage to include one more.
You cannot chain leftJoin (or any join) in Drupal queries, because leftJoin() returns the alias, not the query. Then you should use execute() to "run" the query.
$or = db_or()
->condition('fd.field_detailed_question_value', '%'.db_like($term ).'%', 'LIKE')
->condition('fb.body_value','%'.db_like($term ).'%' , 'LIKE');
$query = db_select('node', 'n');
$query->fields('n');
$query->leftJoin('field_data_body' , 'fb', 'fb.entity_id=n.nid');
$query->leftJoin('field_data_field_detailed_question' ,'fd', 'fd.entity_id=n.nid');
$query->condition($or);
$stmt = $query->execute(); // execute the query (returns the "statement" to fetch).
while ($row = $stmt->fetchObject()) {
//..
}
You have to add fields :
$query = db_select('node', 'n')->fields('n');
or
$query = db_select('node', 'n')
->addField('n','title')
->addField('n','nid');