Search code examples
mysqljoindrupal-7

sql query for displaying full node


Hi I'm looking to pull node content from a Drupal 7 database to a custom PHP file using a custom query. I can see field_data_body and field_revision_body contain parts of the node but am struggling to build the join and to know what to join ON, which join to use and why. Please can someone assist? I have got as far as:

SELECT * FROM field_data_body INNER JOIN field_revision_body
ON entity_id = entity_id WHERE entity_id = 1

...which returns '#1052 - Column 'entity_id' in where clause is ambiguous' - which is where my limited MySQL knowledge falls flat on its face. Help!


Solution

  • You need to specify from which table you query field entity_id, since it resides in both tables:

        SELECT * FROM field_data_body INNER JOIN field_revision_body
        ON field_data_body.entity_id = field_revision_body.entity_id 
        WHERE field_data_body.entity_id = 1