Yes, but only with the latest Oracle version which is 11g Release2
There you can use the standard ANSI syntax with recursive common table expressions (which also works with nearly every other database except MySQL)
WITH RECURSIVE depTree (pkaid, fkaid) as
SELECT pkaid, fkaid
WHERE pkaid = 1
SELECT t2.pkaid, t2.fkaid
FROM table_with_no_name t2
INNER JOIN depTree ON depTree.pkaid = t2.fkaid
Just change the WHERE pkaid = 1 in the first part of the union to define your "starting point"
thanks....I need general logic because application runs on mysql and oracle both....
If you have to cope with the limited features of MySQL then you will need to either write a procedure to retrieve this or use a different approach for storing the hierarchy e.g. using nested sets - which is explained in the MySQL manual.