1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

Hierarchy problem in sql query

Discussion in 'SQL PL/SQL' started by aadityainpccs, Dec 14, 2013.

  1. aadityainpccs

    aadityainpccs Active Member

    Messages:
    52
    Likes Received:
    2
    Trophy Points:
    160
    Location:
    New delhi (INDIA)
    Hello Experts,

    I am using oracle 11g database with sql developer tool at windows 7.I am trying to make hierarchy for my table data.I have a table tbl_state as
    -------------------------------------------------------------------
    State_Code---State_Name-------Country_Code
    1------------------AH------------------0
    2------------------BH------------------91
    3------------------CI-------------------72
    4------------------DI-------------------72
    5------------------EH------------------91
    6------------------FI-------------------72
    7------------------GJ-------------------83
    8------------------HJ-------------------83
    --------------------------------------------------------------------


    I want hierarchy as: set all states under their country for this I have tried a query as:

    but there is no output as i want.Please suggest me what is going wrong here and if there is any better optimized way to make such hierarchy then please give me.
    here is the database table structure and desired output:

    thank you

    regards

    aaditya
     
  2. krasnoslobodtsev_si

    krasnoslobodtsev_si Forum Genius

    Messages:
    626
    Likes Received:
    129
    Trophy Points:
    810
    Location:
    Russian Federation