[SalesForce] SOQL join in a Parent Child for same table (Account)

I want to write this simple soql query where in Account there is a ParentId and with it would want to bring the name of this parent (Hierarchy field)
Something like:

select Id, Name, (select Name from Account__r where Id = Account.ParentId)
From Account where id = [xxxxxxx]

I know my Where statement is wrong, just wanted to clarify what it is I want
I have seen many examples of join but never where it is the same table.

Best Answer

You do not need any additional filters to make sure the children are related to the parent. If you write the below query, each row will have an attribute named ChildAccounts which contains each Account record whose ParentId matches the row's own Id value.

SELECT Name, (SELECT Name FROM ChildAccounts) FROM Account

If you want to select the parent record instead of children, you would instead do:

SELECT Parent.Name FROM Account
Related Topic