title: How to do multiple layer of query in corda , from one schema to another
body: <p>So i want to query 3 states in corda but i will only get one query criteria from user. so i will query 1st state from the query criteria , now i will query 2nd state with a specific value from 1st state result and in the last i will query the 3rd state from a specific result from the 2nd state.
  and in the last i will feats a specific value from the 3rd state </p>
  
  <p>so can any one explain me how to do it. I have tried it but it is returning null value 
  <strong>here is my code</strong></p>
  
  <pre><code> @GetMapping("PledgeData")
      public APIResponse&lt;List&lt;String&gt;&gt; getPledgeData(@RequestParam("pledgeIdFromUser") String pledgeIdFromUser){
  
          //from the user i have taken the PledgeId and using it as a query criteria
  
      try {
          FieldInfo pledgeId1 = null;
          try {
              pledgeId1  = getField("pledgeId", PledgeSchema.PersistentPledge.class);
  
          } catch (NoSuchFieldException e) {
              e.printStackTrace();
          }
          QueryCriteria allDataRelatedToPledgeIdInPledgeState = new QueryCriteria.VaultCustomQueryCriteria
                  (Builder.equal(pledgeId1, pledgeIdFromUser));
  
          List&lt;StateAndRef&lt;PledgeState&gt;&gt; results1 = activeParty.vaultQueryByCriteria
  
                  ( allDataRelatedToPledgeIdInPledgeState, PledgeState.class).getStates();
  
  // so i have retrieved all the branchId from PledgeState using pledge id
  
          List&lt;String&gt; allBranchIds =results1.stream().map(stateStateAndRef -&gt; stateStateAndRef.getState().getData().getBranchId()).collect(Collectors.toList());
  
          // now i want to iterate all the branchID to find the winner in PledgeUpdateState
          //so here my input will be branchID
  
          List&lt;String&gt; allWinner = null;
          for(String allBranchId:allBranchIds ){
              FieldInfo branchId = null;
              try {
              branchId  = getField("branchId", PledgeResultSchema.PersistentPledge1.class);
              } catch (NoSuchFieldException e) {
                  e.printStackTrace();
              }
              QueryCriteria allDataRelatedToPledgeIdInPledgeUpdateState = new 
                  QueryCriteria.VaultCustomQueryCriteria(Builder.equal(branchId, allBranchId));
  
              List&lt;StateAndRef&lt;PledgeUpdateState&gt;&gt; results2 = activeParty.vaultQueryByCriteria
                      ( allDataRelatedToPledgeIdInPledgeUpdateState, PledgeUpdateState.class).getStates();
              allWinner  = results2.stream().map(stateStateAndRef -&gt; stateStateAndRef.getState().getData()
                      .getWinner()).collect(Collectors.toList());
          }
  
          // now here i want to return all the winner in the PledgeUpdateState
  
          return APIResponse.success(allWinner);
      }catch (Exception e){
              return APIResponse.error(e.getMessage());
          }
  
      }```
  </code></pre>