Last active
December 22, 2015 14:19
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mlid int(10) unsigned NO PRI 0 | |
nid int(10) unsigned NO UNI 0 | |
bid int(10) unsigned NO MUL 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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