Skip to content

Instantly share code, notes, and snippets.

@gavinblair
Created July 20, 2010 14:19
Show Gist options
  • Save gavinblair/483014 to your computer and use it in GitHub Desktop.
Save gavinblair/483014 to your computer and use it in GitHub Desktop.
Drupal 6: Get node titles and menu titles from all nodes of a type.
SELECT node.title, node.nid, menu_links.link_title FROM node
LEFT JOIN menu_links ON (link_path = CONCAT('node/', node.nid))
WHERE node.type = 'page'
@gavinblair
Copy link
Author

The interesting thing here is the LEFT JOIN.

m.link_path contains the node id, but it's always preceded by "node/". For example, the link_path of node 2 is "node/2". Using CONCAT we can take that into consideration.

@SeanJA
Copy link

SeanJA commented Jul 20, 2010

Dude... don't be so lazy :P. Type out the whole name of the tables (especially when they are that short), using table aliases just adds to confusion in long queries.

@gavinblair
Copy link
Author

It's a short query, kept short by aliases. A lazy programmer is a happy programmer. :P

@SeanJA
Copy link

SeanJA commented Jul 21, 2010

Not so good for examples though, seeing as it scrolls to the right :P

@gavinblair
Copy link
Author

Updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment