Skip to content

Instantly share code, notes, and snippets.

@vincenzo
Last active December 22, 2015 14:19
Show Gist options
  • Save vincenzo/6484810 to your computer and use it in GitHub Desktop.
Save vincenzo/6484810 to your computer and use it in GitHub Desktop.
DRUPAL - Retrieve all nodes that were children in a Book and whose root parent was of a specific node type
mlid int(10) unsigned NO PRI 0
nid int(10) unsigned NO UNI 0
bid int(10) unsigned NO MUL 0
<?php
$query = db_select('book', 'b')->distinct();
$query->innerJoin('node', 'n', 'b.bid = n.nid');
$query->innerJoin('book', 'bb', 'b.bid <> b.nid');
$query->addField('b', 'nid');
$query->condition('n.type', 'project', '=');
$query->orderBy('b.nid');
SELECT b.nid
FROM book b INNER JOIN node n ON b.bid=n.nid
WHERE b.bid <> b.nid AND n.type = 'project' ORDER BY b.nid;
SELECT DISTINCT b.nid
FROM book b
INNER JOIN node n ON b.bid = n.nid
INNER JOIN book bb ON b.bid <> b.nid
WHERE n.type = 'project'
ORDER BY b.nid;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment