There are two methods to achieve your task.
Utilize StandardController
controller provided by salesforce. This allows you to <apex:relatedList>
which displays the relatedlist of any particular record. For example, if you're implementing standardcontroller
for Account
then for a particular record of Account
it will display it's related list such as Contacts, Opportunities etc.
Fetch the record along with it's related list. Just the way as @AlexanderBerehovskiy highlighted.
Method 1
<apex:page standardController="Account" extensions="Acc">
<apex:form>
<apex:relatedList list="CombinedAttachments" >
<apex:facet name="header">Notes and Attachments</apex:facet>
</apex:relatedList>
</apex:form>
</apex:page>
Method 2
VF Page:
<apex:page standardController="Account" extensions="Acc">
<apex:form>
<apex:pageblock >
<apex:pageBlockSection >
<apex:inputField value="{!myAcc.name}"/>
<apex:inputField value="{!myAcc.id}"/>
</apex:pageBlockSection>
<apex:pageBlockTable value="{!myacc.attachments}" var="attach">
<apex:outputField value="{!attach.Id}"/>
<apex:outputField value="{!attach.Name}"/>
</apex:pageBlockTable>
</apex:pageblock>
</apex:form>
</apex:page>
Apex Controller:
public Account myAcc{get;set;}
public Acc(ApexPages.StandardController controller) {
myAcc= [SELECT id, name, (Select id,name from Attachments) FROM Account WHERE id = '0012800000EK4iY'];
}
ParentId = Id
because you are using inner query and main query is your parent.