You can use the following code.
$query = db_select('digitaliq_flds_by_node', 'a')->fields('a');
$alias = $query->join('digitaliq_fld_category', 'b', 'a.fld_id = %alias.fld_id AND a.fld_collection_id = %alias.fld_collection_id AND a.fld_group_name = %alias.fld_group_name');
$terms = $query->execute();
Calls to SelectQuery::join()
(like SelectQuery::leftJoin()
, SelectQuery::innerJoin()
, and SelectQuery::addJoin()
) aren't chain-able because those methods don't return a SelectQuery
object, but the actual alias used for the join. If you execute the following code, you would get an error.
$query = db_select('digitaliq_flds_by_node', 'a')
->fields('a')
->join('digitaliq_fld_category', 'b', 'a.fld_id = %alias.fld_id AND a.fld_collection_id = %alias.fld_collection_id AND a.fld_group_name = %alias.fld_group_name')
->execute();
Strings in PHP are not objects nor they define an execute()
method.
To verify the code is executing the right SQL query, cast $query
to a string, and print it. You will get the SQL query that would be executed from your code.
$query = db_select('digitaliq_flds_by_node', 'a')->fields('a');
$alias = $query->join('digitaliq_fld_category', 'b', 'a.fld_id = %alias.fld_id AND a.fld_collection_id = %alias.fld_collection_id AND a.fld_group_name = %alias.fld_group_name');
print $query;
With that code, I get the following output.
SELECT a.*
FROM
{digitaliq_flds_by_node} a
INNER JOIN {digitaliq_fld_category} b ON a.fld_id = b.fld_id AND a.fld_collection_id = b.fld_collection_id AND a.fld_group_name = b.fld_group_name