title: How to get records n levels tree with exact number of child using mysql query
body: <p>I'm stuck to find n-levels of tree records with exact number of child nodes.</p>
  
  <p>Let me explain in brief what I expected output using MySQL query</p>
  
  <pre><code>All users has exact number of child users for example 2
  </code></pre>
  
  <p>Please check the following image<a href="https://i.stack.imgur.com/mvnlR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mvnlR.png" alt="enter image description here"></a></p>
  
  <p>If levels has exact number of users then that level is completed otherwise its incomplete.</p>
  
  <p>here is my table</p>
  
  <pre><code>CREATE TABLE `users` (
    `id` bigint(20) UNSIGNED NOT NULL autoincrement,
    `first_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
    `last_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
    `parent_id` bigint(20) UNSIGNED DEFAULT NULL,
  );
  </code></pre>
  
  <p>Can you please anyone help me for the same.</p>
  
  <p>Your help would be appreciated.</p>
  
  <p>Thanks</p>