Skip to content

Instantly share code, notes, and snippets.

@matthewpoer
Created May 2, 2017 13:11
Show Gist options
  • Save matthewpoer/58e9f348fc244ecf40e4de926a3f3668 to your computer and use it in GitHub Desktop.
Save matthewpoer/58e9f348fc244ecf40e4de926a3f3668 to your computer and use it in GitHub Desktop.
Select the Account ID, Name and Parent ID and Name for all Sugar Accounts with Parents
select
accounts.id as account_guid,
accounts.name as account_name,
accounts.parent_id as parent_account_guid,
parents.name as parent_account_name
from accounts
join accounts parents
on parents.deleted = 0
and accounts.parent_id = parents.id
where accounts.deleted = 0
and accounts.parent_id is not null
and accounts.parent_id <> ''
order by parent_account_name asc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment