Question: I am trying to get the child record based on parent id as well as some criteria from parent to child. However it is failing as where clause in inner doesnot give child record . Is there any workaround possibile

```
String SOQL='SELECT Order_N_c, ( 
                  SELECT Account__r.name,Account__c, Opportunity__r.name 
                  FROM Order_Mps__r 
                  WHERE '+selectedFilter.trim() +'=: inputSrch) 
             FROM Order__c WHERE id in:parentids)';

```

Is there any workaround other then reversing the query.

Answer: 
I would do the inverse query.

Example:

```
String soql = 'SELECT Account__r.name,Account__c, Opportunity__r.name, Order__r.Order_N_c
                  FROM Order_Mps__r 
                  WHERE '+selectedFilter.trim() +'=: inputSrch
                  AND Order__c IN : parentids';

```

With this query you obtain the childs record and inside the child you will have a record with the data of the parent.
You have an extra `)` in the last line of your soql. 

```
FROM Order__c WHERE id in:parentids)';

```

Use the following instead

`FROM Order__c WHERE id in:parentids';`

Reversed (child-to-parent) version of your soql would roughly be

```
SELECT Account__r.name, Account__c, Opportunity__r.name , Order__r.Order_N_c
FROM Order_Mps__c 
WHERE '+selectedFilter.trim() +'=: inputSrch
AND Order__c in: parentids

```

In order to understand the relationship names, and referencing children in parent or vice versa, have a look at this [article](https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_and_custom_objects.htm).