In salesforce SOQL there are two type of subquery.
1. from parent object to the child object subquery .
suppose you try to fetch Account(parent) records and related all Contacts(child)
then use this subquery
list<Account> lstAccountToContact = [select Id,Name,(select Id,Name from Contacts) from Account];
system.debug(lstAccountToContact.get(0).Contacts.Name);
2. from child object to the parent object subquery.
list<Contact> lstContactToAccount = [select Id,Name,Account.Id,Account.Name from Contact];
system.debug(lstContactToAccount.get(0). Account.Name);