Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DanLaufer/70020bcb03d8ea6e7c7dd22f2857063d to your computer and use it in GitHub Desktop.
Save DanLaufer/70020bcb03d8ea6e7c7dd22f2857063d to your computer and use it in GitHub Desktop.
Drupal 8 - SQL - Search for node in DB with specific field value
//Join node table with a field table and search for published nodes of a certain type with a specific field value:
SELECT node.nid AS node_id,
LEFT(node.title, 10) AS node_title, field_data_field_reference_database_id.field_reference_database_id_value as ref_id
FROM node
LEFT JOIN field_data_field_reference_database_id
ON node.nid = field_data_field_reference_database_id.entity_id
WHERE type='location'
AND status='1'
AND field_data_field_reference_database_id.field_reference_database_id_value IS NULL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment