Q:

Invalid Field Error trying to get child record

I'm trying to create a dynamic query.  I'll just simplify the code for better understanding.  So for example my code looks like this. 
String fieldName = '(Select id from care_applications__r)';
String sObjectName = 'Account';
String recordId = '123456789';
String query;
List<Sobject> listSobject = new List<Sobject>();

query = ' SELECT ID,' + fieldName + ' FROM ' + sObjectName + ' WHERE Id = \'' + recordId + '\'';

recordList = Database. Query(query);

The thing is when I'm using query editor of developer console.  I was able to get the child record id's
But when I try to debug the recordList.  I can't seem the get the child Id's instead it's giving me the accountId not the child record Id
and when I'm trying to access it like for example. 
System.debug(recordList[0].get(fieldName));

It will throw me an Invalid Field (Select Id From Care_Applications__r);
I don't know if I'm missing on something because my code looks fine.  Thank you in advance. 
I'm using the code btw as a controller for lightning component. 

A:

To get the child records from the SOQL you need to use ChildRelationship name that is "care_applications__r" in your case. 
Whenever we are using the inner query to get the child records then we always use the relationship name. 
For example, We are using below Query to get the contacts related to an Account. 
Select id, Name, (Select Id, Name From Contacts) From Account

Now, we wanted to retrieve the contacts records then use relationship name which is Contacts
accountList[0].Contacts
To get the relationship name.  Go to child Object(Contact) Open the relationship Field (Account) and see the Relationship name there

Use below code for your case: - 
System.debug(recordList[0].care_applications__r);

Edit: - 

In case of Custom Object, you need to append __r in relationship name

A:

If you refer to Understanding Query Results, and refer to the Parent-to-Child example, you will find the query and explanation as below. 
SELECT Id, Name,
  (
    SELECT Id, FirstName, LastName
    FROM Contacts
  )
FROM Account
WHERE Name like 'Acme%'

This query returns a set of accounts, and within each account, a query result set of Contact fields containing the contact information from the subquery. 

So in order to fetch the results in Apex, you will need to parse the "query result" of Contacts and then retrieve their fields accordingly.  So your apex logic will look something as below (just replace the reference of contacts with your relationship name):
List<Sobject> slist = Database.query('Select Id, Name, (Select Id, Name From Contacts) From Account limit 5');
for(SObject s : slist) {
    Account a = (Account) s;
    system.debug('Account Name:' + a.Name);

    List<Contact> contacts = a.Contacts; // replace this with your relationship name
    for(Contact c: contacts) {
        system.debug('Contact Name:' + c.Name);
    }
}

