I want to fetch some data from the following database table ‘article’.

i want to fetch an article information whose category_id is 4. But the result should contain all the records of its parent categories.
for example :
‘article1’ has parent ‘Sub Category1’ and its parent is ‘Main Category’. So the result should have the rows 1,2,4 from the table.
Is it possible to write one SQL query for this? what will be the query which can fetch data according to above condition?
Please guide me..!!
thanks..
Please refer to this article: Managing Hierarchical Data in MySQL.
Actually, they have purposed model to get Hierarchical data without recursion.
In that they use lft(left) and rgt(right) this to extra column for storing structural information of table. lft and rgt are set as follows
Root lft is 1. then its first child lft is next number then its child in next number so on till there are no child then for that node (leaf node) rgt will be its lft +1.
And we will set siblings lft as rgt +1 and follow same rules for it also.
And if all child’s numbering is done its will set parents rgt to last child’s rgt +1.
I haven’t explain it neatly but on link with image it is easier to understand.
So after this you can easily explore nested structure using following queries
For getting all parent’s id in order:
For DELETING any row :
For inserting any row:
This is somewhat complex, but after creating stored procedure, it will not be difficult to use.