I am currently moving a website from Drupal. The information I need to transfer is divided to many DB tables and connected through entity_id (That is my understanding, I have no experience in Drupal).

E.g. I have 2 MySQL tables:
users — contains uids, passwords and emails
field_revision_field_user_profile_phone — contains phone numbers and entity_ids

I believe there should be a table that matches uids and entity_ids, that will let me build a MySQL query to join them, but I can't find it.

How do I join those tables?


2 Answers 2


In the database that contains entity_id (field_revision_field_user_profile_phone in this case) there is a column named entity_type. That would be a name of the table which contains both uid and entity_id.


For the second question how to join tables:

You can use Drupal db_select or db_query in querying the database and joining tables.

This will list all users name, mail, and password.


Using db_select

$query = db_select('users', 'u');
$query->join('field_revision_field_user_profile_phone', 'ei', 'ei.entity_id = u.uid');
$query->fields('ei', array('field_user_profile_phone_value'));
$query->fields('u', array('name', 'mail', 'pass'));

$results = $query->execute()->fetchAll();
foreach($results as $result) {
  // ...

Using db_query

SELECT ei.field_user_profile_phone_value AS field_account_employee_id_value,
       u.name AS name,
       u.mail AS mail,
       u.pass AS pass
FROM users u
INNER JOIN field_revision_field_user_profile_phone ei ON ei.entity_id = u.uid

Additional Resources:

Documentation of db_select function.

Documentation of db_query function

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.