How can I improve ths logic : I will have to implement following logic in java - 

1. execute query Q1 on data D1 based on condition C1
2. if result of Q1 is more than zero then make another query Q2 on data D2 based on condition C2
3. If Q2 size is more than zero then make another query Q3 on data D2 based on condition C3
4. If Q3 size is more than zero then make another query Q4 on data D2 based on condition C4

5. Now if Q1 result size is zero then execute query Q5 on data D1 based on condition C5
6. If result of Q5 is more than zero then execute query Q6 on data D3 based on condition C2
7. If result of Q6 is more than zero then execute query Q7 on data D3 based on condition C3
8. If result of Q7 is more than zero then execute query Q8 on data D3 based on condition C4

So I'm thinking about to write below logic - 

     R1 = getResult (dataset D1, condition C1); //Query on data D1 based on  condition C1;
      If (R1 is not null)
         {
              R2  = getResult (dataset R1, condition C2);
                                                         //  Query on data R1 based on condition C2;
                                                  if(R2 is null){
                                                         R3 = getResult (dataset R1, condition C3); 
                                                                                  // Query on data R1 based on condition C3
                                                                                if(R3 is null){
                                                                                  R4 = getResult (dataset R1, condition C4);
                                                                                    // Query on data R1 based on condition C4
                                                                                                display(R4);
                                                                                }else{
                                                                                   display(R3);
                                                                                  }
                                                                                }else{
                                                                                display(R2);
                                                                                }
           
         }else{
                                               R5 = getResult (dataset D1, condition C5);
                                                if(R5 is not null){
                                                     R6 = getResult (dataset R5, condition C2);
                                                                                //Query on data R5 based on condition C2;
                                                                                if(R6 is null){
                                                                                R7 = getResult (dataset R5, condition C3);
                                                                                //Query on data R5 based on condition C3
                                                                                if(R7 is null){
                                                                                    R8 =  getResult(dataset R5, condition C4);
                                                                                                //Query on data R5 based on condition C3
                                                                                                }else{
                                                                                                display(R8); 
                                                                                                }
                                                                                }else{
                                                                                display(R6);
                                                                                }
                                                }
                                
           }

Is there a better way to improve this logic?