List parent terms by vocabulary
Firstly you add a cck field named flag for levels to your vocabulary when created, then after that when you import or add terms in this then fill flag value like "My First Level"/"My Second Level". then you can fetch very easily like that..`

/* Get All States From Taxonomies */
  function get_taxonomy_by_flag($flag) {
       $VocabName = "Master Data";
          $myStateArray = array(0=&gt;'-- Select --');
        $Vocabluary = get_vocabulary_by_name($VocabName);
         $query = new EntityFieldQuery();
          $entities = $query-&gt;entityCondition('entity_type', 'taxonomy_term')
-&gt;propertyCondition('vid', $Vocabluary-&gt;vid)    
-&gt;fieldCondition('field_flag', 'value', $flag, '=')    
-&gt;execute();
if(sizeof($entities)&gt;0)
{       
  foreach($entities['taxonomy_term'] as $tid) {

    $term = taxonomy_term_load($tid-&gt;tid);     
    $name=$term-&gt;name;
    $myStateArray[$term-&gt;field_code['und']['0']['value']] = $name;    
  }   
  return $myStateArray;     
}
else
{
    return 0;
 }    
}

    function get_vocabulary_by_name($vocabulary_name) {
        $vocabs = taxonomy_get_vocabularies(NULL);
         foreach ($vocabs as $vocab_object) {
          if ($vocab_object-&gt;name == $vocabulary_name) {
            return $vocab_object;
         }
      }
            return NULL;
      }
     call this function by flag name and you can easily get all parents. because i have used this for **State/District/Block/Village** purpose.
      get_taxonomy_by_flag('STATE');


hope this helps you lot...