How to perform join with multiple columns using db_select?
You can use the following code.

$query = db_select('digitaliq_flds_by_node', 'a')-&gt;fields('a');

$alias = $query-&gt;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-&gt;execute();


Calls to SelectQuery::join() (like-wise 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')
  -&gt;fields('a')
  -&gt;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')
  -&gt;execute();


Strings in PHP are not objects, and they don't define the 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')-&gt;fields('a');
$alias = $query-&gt;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 this 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