I see this question was asked for Drupal 7, but the menu_link table doesn't exist in Drupal 9.

Is there a SQL query for listing all nodes that are not assigned to a menu?

  • You could consider adjusting the SQL query from this answer to the new table and column names drupal.stackexchange.com/a/171719/47547 and post the answer. Or wait until someone else needs it for a project. The last time this took three years.
    – 4uk4
    Sep 27 at 9:43

1 Answer 1


In Drupal 9 can use this 'menu_link_content_data' table to find whether node has any reference as menu:

Snippet code for finding all nodes not referenced by a// Get all nodes.

$nids = \Drupal::entityQuery('node')
if (isset($nids) && !empty($nids)) {
  foreach($nids as $nid){
    // Check nid has reference as menu
    $rst =  \Drupal::database()->select('menu_link_content_data', 'mn')
      ->condition('mn.link__uri', 'entity:node/'.$nid, '=')
    // If nid has no reference as menu then insert nid in $nodes[]
     $nodes[] = $nid;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.