Home » SQL & PL/SQL » SQL & PL/SQL » need help on writing query for a complex situation (oracle 10)
icon4.gif  need help on writing query for a complex situation [message #313220] Fri, 11 April 2008 02:00 Go to next message
jaibazz
Messages: 1
Registered: April 2008
Junior Member
hi,
I have a requirement where i write a query to fetch category_details for a user_id
(i.e) for a given user_id which is primary key in a table ,i take it and map it another table where this becomes a foreign key and fetch the corresponding category_id for it now this category_id is primary key in another table so i take this category_id and go to another table and fetch its corresponding description for it.now the problem is i have a parent_category_id field in that table where i mp to category_id .each category_id has a corresponding decription for it .now in the smae table i have to say for eg
if category_id parent_category_id description
3 5 parts
5 0 bulletins
now i have to iterate in a way that first i have to fetch the description of category_id = 3 then tkae its parent_category_id 5 which itself is a category_id just a parent of category_id 3,now i have to fetch the description of parent_category_id 5 which bulletins and and have do this till the parent_category_id for a category_id = 0.eventually i need to get a result for this eg like description for this category_id 3 after all iterations as bulletins->parts..
kindly help on how to proceed with the queries for this
Re: need help on writing query for a complex situation [message #313229 is a reply to message #313220] Fri, 11 April 2008 02:54 Go to previous messageGo to next message
Michel Cadot
Messages: 64139
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Post a test case: create table and insert statements.
Also post the result you want with these data.
Don't forget to format your post when you'll post this.

Also always post your Oracle version (4 decimals).

Regards
Michel
Re: need help on writing query for a complex situation [message #313234 is a reply to message #313229] Fri, 11 April 2008 03:02 Go to previous message
skooman
Messages: 912
Registered: March 2005
Location: Netherlands
Senior Member
And OP: in the meantime I would look up "connect by prior" in the SQL reference if I were you...
(sounds like that is what you are looking for).
Previous Topic: dynamic list of dates
Next Topic: Most disk space-efficient number type?
Goto Forum:
  


Current Time: Thu Dec 08 20:13:55 CST 2016

Total time taken to generate the page: 0.08010 seconds