Saturday, May 2, 2009

Self join

You have to use alias for self join.
List all accounts with their parent account.

SELECT t1.ACCOUNT_NAME, t2.ACCOUNT_NAME AS PARENT_ACCOUNT
FROM ACCOUNT t1, ACCOUNT t2
WHERE t1.PARENT_ACCOUNT_ID = t2.ACCOUNT_ID(+)
Use outer join here to list accounts without parents.

No comments:

Post a Comment

Oracle Query