First of all this question is similar to  one but the difference is that I have an unknown quantity of parents. Is is possible and if so how would I get all parents of a child when I only know the Id of any child? I have a table like: +----+------------+----------+--------+ | Id |    name    | position | parent | +----+------------+----------+--------+ |  1 |        top |        1 |   NULL | |  2 |     middle |        1 |      1 | |  3 | bottom_1_1 |        1 |      2 | |  4 | bottom_1_2 |        2 |      2 | |  5 |   middle_2 |        2 |      1 | |  6 | bottom_2_1 |        1 |      5 | |  7 | bottom_2_2 |        2 |      5 |  Which would correspond to something like this visually: top  Ͱ middle     Ͱ bottom_1_1     Ͱ bottom_1_2  Ͱ middle_2      Ͱ bottom_2_1     Ͱ bottom_2_2  Unfortunately my knowledge of MySQL is not advanced enough to show some kind of foreach join method to give you as an example as I would only be able to go up 1 in the tree like: SELECT * FROM table WHERE Id in (7, (SELECT parent FROM table WHERE Id = 7))  This would return: +----+------------+----------+--------+ | Id |    name    | position | parent | +----+------------+----------+--------+ |  5 |   middle_2 |        2 |      1 | |  7 | bottom_2_1 |        2 |      5 |  But I would need something like the example below as the first entry of the above example still has a parent +----+------------+----------+--------+ | Id |    name    | position | parent | +----+------------+----------+--------+ |  1 |        top |        1 |   NULL | |  5 |   middle_2 |        2 |      1 | |  7 | bottom_2_1 |        2 |      5 |
Assume you have a flat table that stores an ordered tree hierarchy:  Id   Name         ParentId   Order  1   'Node 1'            0      10  2   'Node 1.1'          1      10  3   'Node 2'            0      20  4   'Node 1.1.1'        2      10  5   'Node 2.1'          3      10  6   'Node 1.2'          1      20   Here's a diagram, where we have [id] Name.  Root node 0 is fictional.                          [0] ROOT                           /    \                [1] Node 1          [3] Node 2               /       \                   \     [2] Node 1.1     [6] Node 1.2      [5] Node 2.1           /            [4] Node 1.1.1   What minimalistic approach would you use to output that to HTML (or text, for that matter) as a correctly ordered, correctly indented tree?   Assume further you only have basic data structures (arrays and hashmaps), no fancy objects with parent/children references, no ORM, no framework, just your two hands. The table is represented as a result set, which can be accessed randomly.   Pseudo code or plain English is okay, this is purely a conceptional question.  Bonus question: Is there a fundamentally better way to store a tree structure like this in a RDBMS?    EDITS AND ADDITIONS  To answer one commenter's ('s) question: A root node is not necessary, because it is never going to be displayed anyway. ParentId = 0 is the convention to express "these are top level". The Order column defines how nodes with the same parent are going to be sorted.  The "result set" I spoke of can be pictured as an array of hashmaps (to stay in that terminology). For my example was meant to be already there. Some answers go the extra mile and construct it first, but thats okay.  The tree can be arbitrarily deep. Each node can have N children. I did not exactly have a "millions of entries" tree in mind, though.  Don't mistake my choice of node naming ('Node 1.1.1') for something to rely on. The nodes could equally well be called 'Frank' or 'Bob', no naming structure is implied, this was merely to make it readable.  I have posted my own solution so you guys can pull it to pieces.
I have created a VF page and used "render as pdf"  &lt;apex:commandButton value="Save to Opportunity" action="{!savePdf}"  /&gt;   Its working fine when i am using above line without rerender and oncomplete but when i am adding rerender or oncomplete it is not working.I am able to save the PDF in attachment folder but when i am trying to open its showing  "Unable to load document"  Even if i remove oncomplete and use Rerender then also its saving the attachment in Attachment object and when i view ,it is not loading and says "Unable to load document"      &lt;apex:commandButton value="Save to Opportunity" action="{!savePdf}"  oncomplete="myClose();"/&gt;   Javascript Code  function myClose(){      self.close();     window.opener.location.href="/{!$CurrentPage.parameters.Id}";  }   Class Code  public void savePdf() {      PageReference pdf = Page.GenerateQuotePDF;     pdf.getParameters().put('id',parentId);      Attachment attach = new Attachment();      Blob body;     body = pdf.getContent();     attach.Body = body;     attach.Name = 'Opportunity'+ '.pdf';       attach.IsPrivate = false;     attach.ParentId = parentId;     attach.ContentType = 'application/pdf';     insert attach;     }     Please help.. Bibtex true unsort What is a good introductory book on quantum mechanics? Unbiased Estimator for a Uniform Variable Support Let $ x_i $ be iid observations in a sample from a uniform distribution over $ \left[ 0, \theta \right] $.  Now I need to estimate $ \theta $ based on $N$ observations and I want the estimator to be unbiased.  I thought about simple estimator $ \hat{\theta} = \max \left( x_i \right) $.  Based on simulation it is not biased, yet I couldn't show it analytically.  Could anyone, please, show it is unbiased?  BTW, I could easily find another, easy to prove, unbiased estimator, $ \hat{\theta} = 2 \mathrm{mean} \left( {x}_{i} \right) $ How to visualize the gradient as a one-form? I am reading Sean Carrol's book on General Relativity, and I just finished reading the proof that the gradient is a covariant vector or a one-form, but I am having a difficult time visualizing this. I usually visualize gradients as vector fields while I visualize one-forms with level sets. How to visualize the gradient as a one-form? What is the SE version of Seven Dirty Words? Caution: R-rated language  Some words, when present in a comment, make it eligible for instant, automatic one-flag deletion. Out of the , only      shit and fuck    appear to work this way. But then there are other, Stack Exchange-specific dirty phrases:    accept rate or accept-rate acceptance rate  what have you tried   whore    Are there other such words or phrases? Is there a complete list of them?     Some suspect words and phrases that do not suffice for automatic deletion:       accept an/the answer, thank you, voting to close, piss, bitch, idiot, cunt (often found on Stack Overflow as a misspelling of "count"). $\sum_{n=1}^\infty \log \frac{n+1}{n}$  $\sum_{n=1}^\infty \log \frac{n+1}{n}$ =  $\displaystyle\lim_{n \to{+}\infty}(\log2 - \log1)+(\log3-\log2)+...+(\log(n+1)-\log n)$=$\displaystyle\lim_{n \to{+}\infty}\log(n+1)\to \infty$. So, the series diverges.  Is my procedure correct? Windows 10 Asks me to Enter a Password I am using Windows 10 Pro x64 on my personal laptop on which I have a single user account with no password. For some reason however, Windows 10 has started asking me to enter a password whenever I boot up my machine. All I have to do is press the button without entering anything, and I log in, but I would much rather skip this step in favor of an automatic sign-in. Why has this started happening only now? What can I do to stop this behavior? Why is there no last activity message? Select list of node titles for a view exposed filter This is inspired by some discussions in .  In the Harry Potter universe, how are Dementors born?  Or are they artificially created by some magical means? Do characters provoke opportunity attack when they leave another character's reach who is not facing them? "You can make an opportunity attack when a hostile creature that YOU CAN SEE moves out of your reach."   In 5E do you have to specify which way your character is facing at all times?  If an enemy who is behind him leaves melee range but his back is to him does that enemy provoke an opportunity attack?    Are enemies within five feet and 360 degrees of a character considered to be within reach?  For example... Kruska and Atone are attacking Dip.  Dip is facing or only attacking Kruska.    Then Atone moves out of Dip's reach (melee range 5 feet) to engage a silly looking wizard.    Does Atone's move provoke an opportunity attack from Dip even though he's not facing him?  Is he assumed to be able to see him? How can I install Skype on 32-bit Ubuntu 14.04? How do I do simple user input in python? How to use SQLDeveloper to connect to embedded Derby database I need to factory reset my Macbook but cannot recall the password. So I used Cmd+R during startup and go to terminal and typed 'resetpassword' according to this advice    Now 'Reset Password' application appears but there is nothing where I have to select the volume containing the user account. Why does this happen? I'm fairly certain this has happened to all of us at some point: You go into a room to get something, but once you're there, you can't remember what you intended to get. It seems like a specific, common phenomenon like this must have a name, but I can't think of it. Does anyone know a name (either formal or slang) for this?  I don't want a general term like forgetfulness or absent-mindedness, which could apply to all sorts of forgetting, or a term for not being able to remember a certain word. I'm looking for a word or phrase that describes this one specific situation of forgetting what you need to get as soon as you go to get it. Android 5.0 (Lollipop) was officially announced on October 15th, 2014.  You can review the high-level changes at the  and the announcement on the official .  Of course, not all devices will get this update right away and others won't get it at all. Each manufacturer and carrier often choose to add their custom modifications which tend to delay the official release.  When will each device get Android 5.0, either officially or unofficially, if ever?  See also: For any prime $p > 3$, why is $p^2-1$ always divisible by 24? For any smooth manifold, is it true that for any two points on the manifold, there exists a chart that covers the two points?