Database¶
This page is about raw SQL queries, etc. to examine database directly.
WHERE vs JOIN¶
A good read: How to design SQL queries with better performance: SELECT * and EXISTS vs IN vs JOINs
Get A Field's Revisions¶
In order to apply any single field, please change
- Field's revision table name
node_revision__field_il_ilce_semt
inFROM
clause - Field's value column name
field_il_ilce_semt_target_id
inSELECT
clause
SELECT
`node_revision`.*,
`fieldrevisions`.`bundle`,
`fieldrevisions`.`delta`,
`fieldrevisions`.`field_il_ilce_semt_target_id` `field_value`
FROM
`node_revision__field_il_ilce_semt` `fieldrevisions`,
`node_revision` `node_revision`
WHERE
`fieldrevisions`.`entity_id` = `node_revision`.`nid`
AND `fieldrevisions`.`revision_id` = `node_revision`.`vid`
AND `fieldrevisions`.`langcode` = `node_revision`.`langcode`
ORDER BY
`fieldrevisions`.`entity_id` DESC;
-- It is better to use join syntax
SELECT
`node_revision`.*,
`generic_field_revisions`.bundle,
`generic_field_revisions`.delta,
`generic_field_revisions`.field_il_ilce_semt_target_id AS field_value
FROM
node_revision__field_il_ilce_semt `generic_field_revisions`
INNER JOIN node_revision `node_revision`
ON `generic_field_revisions`.entity_id = `node_revision`.nid
AND `generic_field_revisions`.langcode = `node_revision`.langcode
AND `generic_field_revisions`.revision_id = `node_revision`.vid
ORDER BY
`generic_field_revisions`.`entity_id` DESC;