i want compare (=) two fields in two tables. In the first field, i have only a nid (e.g. 55) and in the second field, the value is formatted with "node/%" (e.g. node/55).

How can I created the join query for compare these two fields ?

I have tested this with this code without success :

$uid = arg(1);
$query = db_select('field_data_field_users', 'alias1');
    ->condition('user_id', $uid, '=')
    //->addExpression('node/(fdfur.entity_id)', 'alias2'); // > not functionnal
$query->join('menu_links', 'ml', 'ml.link_path = alias1.entity_id');
// ml.link_path = alias1.entity_id > node/55 = 55 > no match...
    ->fields('alias1', array('entity_id'))
    ->fields('ml' , array('language'))
    ->fields('ml' , array('link_path'))
$results = $query->execute();

Here an image that explains my problem see image

I start from the user id and I want to get the datas of the menu links. The first db_select in the custom table is ok, i get the related nids with the user ids, but I can't to get the datas of the menu link.

Have you any idea to resolve my problem ?

Thanks for your help.

1 Answer 1


I suspect this is what you are looking for

db_query("SELECT * FROM node LEFT JOIN url_alias ON url_alias.alias=concat('node/',node.nid)");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.