I have a table that looks like this:    Where EMP has a child SEG and it has a children SUP and so on... What I would like to do is find the full hierarchy EMP>SEG>SUP>DIR>REG>GOP in any of the children based in something like 'where' clause (something like: 'where inferior_codigo = SUP0001'), they should return me all the hierarchy of this particular item.   I did something like this but i can only find the parent or children, not both at the same time, with something like this:      SELECT s1.inferior_codigo AS lv1, s2.inferior_codigo AS lv2, s3.inferior_codigo AS lv3, s4.inferior_codigo AS lv4, s5.inferior_codigo AS lv5, s6.inferior_codigo AS lv6 FROM subs AS s1 LEFT JOIN subs AS s2 ON s2.superior_codigo = s1.inferior_codigo LEFT JOIN subs AS s3 ON s3.superior_codigo = s2.inferior_codigo LEFT JOIN subs AS s4 ON s4.superior_codigo = s3.inferior_codigo LEFT JOIN subs AS s5 ON s5.superior_codigo = s4.inferior_codigo LEFT JOIN subs AS s6 ON s6.superior_codigo = s5.inferior_codigo  WHERE s1.superior_codigo = 'EMP0001' LIMIT 25;   Which will result in the following:    Can someone tell me what I should do to accomplish this? Thanks in advance :)
note: this question has been updated to reflect that we are currently using MySQL, having done so, I would like to see a how much easier it would be if we switched to a CTE-supporting database.  I have a self-referencing table with a primary key, id and a foreign key parent_id.  +------------+--------------+------+-----+---------+----------------+ | Field      | Type         | Null | Key | Default | Extra          | +------------+--------------+------+-----+---------+----------------+ | id         | int(11)      | NO   | PRI | NULL    | auto_increment |  | parent_id  | int(11)      | YES  |     | NULL    |                |  | name       | varchar(255) | YES  |     | NULL    |                |  | notes      | text         | YES  |     | NULL    |                |  +------------+--------------+------+-----+---------+----------------+   Given a name, how can I query the top-level parent?  Given a name, how can I query all of the id's associated with a record of name = 'foo'?  context: I am not a dba, but am planning to ask a dba to implement this type of hierarchical structure and would like to test some queries. The motivation for doing so is described by .    Here is an example of the relationships among ids in the table:    -- ----------------------------------------------------- -- Create a new database called 'testdb' -- ----------------------------------------------------- SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';  CREATE SCHEMA IF NOT EXISTS `testdb` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ; USE `testdb` ;  -- ----------------------------------------------------- -- Table `testdb`.`observations` -- ----------------------------------------------------- CREATE  TABLE IF NOT EXISTS `testdb`.`observations` (   `id` INT NOT NULL ,   `parent_id` INT NULL ,   `name` VARCHAR(45) NULL ,   PRIMARY KEY (`id`) ) ENGINE = InnoDB;  SET SQL_MODE=@OLD_SQL_MODE; SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;  -- ----------------------------------------------------- -- Add Example Data Set -- -----------------------------------------------------   INSERT INTO observations VALUES (1,3), (2,5), (3,NULL), (4,10),     (5,NULL), (6,1), (7,5), (8,10), (9,10), (10,3);
Diamond is not shown for mod name under wiki posts If a diamond mod is an author of a wiki post then the diamond is not displayed besides the mod name. E.g. :        Even when the name refers to the user profile page (in case of more then one author) like in :        Is it intentional or a bug? How many ways can you divide $9$ students into three unlabeled teams where one team contains $4$ people, one contains $3$ people and the last contains $2$ people? Unlabeled, meaning that groups with abc = bca = cba, etc  I understand how to do this if the teams are labeled:  $$\frac{9!}{4!3!2!}$$  But there is a term missing in the denominator when the teams are unlabeled and I'm having difficulty understanding how to calculate how many ways the teams can be organized.  There are $3!$ ways to organize the same first group of $3$, $4!$ ways to organize the same second group of $4$ and $2!$ ways to organize the last group of $2$. Why wouldn't you multiply $3!4!2!$ in the denominator?   For instance:  (ABC, DEFG) = (ABC, DEGF)  = (ABC, DFEG) = (ACB, DFGE), etc What is the reasoning behind restricting the number of migration paths? On the religion and culture stackexchange sites, many, many users will initially ask a question in a place that's kind of off-topic there, but are fully on-board elsewhere.    Christianity.SE, for example, gets a lot of general philopsophical questions that would be better on Philosophy, historical questions that might be better on History.SE, and hermenutical questions that are better on BH.SE.  It is, however, unreasonable in my mind for a user with a question to be required to have domain expertise on which sub-site each has. Indeed, even amongst users with a high amount of knowledge, there can be disagreement.  Likewise, , but as just about every one of those is in beta, the user would have to be very saavy (or would have to find that post) in order to nail it every time.  That said, recommending that a question be moved is much harder than it needs to be.  I have seen business rule logic that says, for example,    migration paths only exist to graduated sites (ergo politics, money, history, and quantitative finance wouldn't qualify) migration paths seem to be limited to 5.   Anything not on a migration path requires a moderator (and not just a high rep user) to get involved.  So, what is the reasoning behind this?  Note, I'm not asking for a solution (although the obvious solution would be to allow migration paths to any established site, beta or not, i.e. a VTC as off topic b/c it belongs on another site should allow you to pick any other site) - I just want to understand the business purpose in restricting migration paths to a small, predefined number for everyone other than a mod. Two "if"s in a row I am developing firefox extension and wanted to count total number of text box of webpage so how to count text box? In my lecture, the lecturer said:      Let $K$ be the key generation algorithm. Given a security parameter represented in unary, $1^k$, $K(1^k)$ will output a keypair $(pk; sk)$, known as the public key and the private (or secret) key, respectively.    My question is: When I want to implement the cryptosystem, how should I represent this $1^k$?  When I implement the key generation procedure, do I literally require callers to pass me a string of $k$ one-bits that the procedure will never use?  And, if so, why is it there in the first place? Difference between JOIN and INNER JOIN Both these joins will give me the same results:  SELECT * FROM table JOIN otherTable ON table.ID = otherTable.FK   vs  SELECT * FROM table INNER JOIN otherTable ON table.ID = otherTable.FK   Is there any difference between the statements in performance or otherwise?   Does it differ between different SQL implementations? Prove $(1-a)(1-b)(1-c)(1-d)&gt;1-a-b-c-d$ and $ a,b,c,d$ are real and between 0 and 1.    I can do this with $$(1-a)(1-b)&gt;1-a-b  \\ 1-a-b+ab&gt;1-a-b  \\ ab&gt;0  $$  But with $c$ and $d$, this becomes much more difficult. Can someone nudge me in the right direction? How can I recover from deleting the /usr/share/themes directory? Do greenhouse gasses make the world habitable? An ageing gent says he does not accept this statement:  It's a fact that greenhouse gases, predominantly water vapour, keep the Earth  from being hostile and cold; that CO2 albeit in trace quantities is also a  greenhouse gas and therefore helps keep the planet warm...   I know no more about why he rejects this statement - maybe it is that water vapour alone would do the job. The gent in question has a first class degree and a doctorate in physics.    Is there a debate within the physics community over this or am I misunderstanding? The square root of a prime number is irrational If $p$ is a prime number, then $\sqrt{p}$ is irrational.  I know that this question has been asked but I just want to make sure that my method is clear. My method is as follows:  Let us assume that the square root of the prime number $p$ is rational. Hence we can write $\sqrt{p} = \frac{a}{b}$. (In their lowest form.) Then $p = \frac{a^2}{b^2}$, and so $p b^2 = a^2$. Hence $p$ divides $a^2$, so $p$ divides $a$. Substitute $a$ by $pk$. Find out that $p$ divides $b$. Hence this is a contradiction as they should be relatively prime, i.e., gcd$(a,b)=1$. shortcut for commands I use following commands very often, and they're too long.  sudo /etc/init.d/kerio-kvc start sudo /etc/init.d/kerio-kvc stop   how can I create a shortcut command for them? something like sudo kerio start or sudo kerio stop How do I install OpenStack? What is the meaning of the "expansion of space"? When we say that "the space between galaxies is expanding," what do we really mean? For instance, if I think of space as being a Cartesian grid, then when space expands should I think of it as adding more grid-points or as making the distance between the grid-points larger? Or is this a flawed picture of space-time even when far from significant mass densities?  It seems to me that it must be the case that we are "adding more grid-points" because otherwise we would not observe the expansion since anything that occupied that part of the grid (e.g. light, my hand, etc.) would also expand by a corresponding amount (otherwise, after a sufficient amount of expansion, we would be able to observe sub-atomic scale processes as being macroscopic in scale). But if it is the case that we are adding more grid-points, then the "expansion" of space seems like a misnomer: shouldn't it be called the "creation" of space?  That being said, either case (adding grid-points or stretching distances) could conceivably be the same process depending on the nature of space-time (i.e. if it were discrete but dense - like the Rationals - rather than either strictly discrete (Integers) or strictly continuous (Reals)... I hope that analogy makes sense).   So what is really going on in intergalactic space? What is the meaning of its expansion? Does it correspond to creating more space, stretching the space that's already there, or something more subtle? IMAP: how to move a message from one folder to another (using the IMAP commands, not with the assistance of any other mail package) What is tail recursion? Evaluation of $\displaystyle \int_{0}^{1}\frac{x\ln (x)}{\sqrt{1-x^2}}dx$   $\bf{My\; Try::}$ Let $\displaystyle I = \int_{0}^{1}\frac{x\ln x}{\sqrt{1-x^2}}dx\;,$ Put $x=\cos \phi\;,$ Then $dx = -\sin \phi d\phi$  and Changing Limit, We get  $$\displaystyle I = -\int_{\frac{\pi}{2}}^{0}\cos \phi \cdot \ln(\cos \phi )d\phi = \int_{0}^{\frac{\pi}{2}} \ln(\cos \phi)\cdot \cos \phi d\phi$$  Now Using Integration by parts, We get  $$\displaystyle I = \left[\ln(\cos \phi)\cdot \sin \phi\right]_{0}^{\frac{\pi}{2}}+\int_{0}^{\frac{\pi}{2}}\frac{\sin^2 \phi}{\cos \phi}d\phi$$  So $$\displaystyle I = \left[\ln(\cos \phi)\cdot \sin \phi\right]_{0}^{\frac{\pi}{2}}+\int_{0}^{\frac{\pi}{2}}\frac{(1-\cos^2 \phi)}{\cos \phi}d\phi$$  So $$\displaystyle I = \left[\ln(\cos \phi)\cdot \sin \phi\right]_{0}^{\frac{\pi}{2}}+\int_{0}^{\frac{\pi}{2}}\sec \phi d\phi-\int_{0}^{\frac{\pi}{2}}\cos \phi d\phi$$  So $$\displaystyle I = \left[\ln(\cos \phi)\cdot \sin \phi\right]_{0}^{\frac{\pi}{2}}+\left[\ln\left|\sec \phi+\tan \phi\right|\right]_{0}^{\frac{\pi}{2}}-\left[\sin \phi\right]_{0}^{\frac{\pi}{2}}$$  So $$\displaystyle I = \left[\ln(\cos \phi)\cdot \sin \phi\right]_{0}^{\frac{\pi}{2}}+\left[\ln\left|\sec \phi+\tan \phi\right|\right]_{0}^{\frac{\pi}{2}}-1$$  Now How can I solve after that, Help Required, Thanks I'm given a matrix A, its dimensions are n x n.  I am required to prove that an invertible matrix B exists, such that the product of the matrices BA is triangular.  Any help? The use of imaginary and complex values comes up in many physics and engineering derivations. I have a question about that: Is the use of complex numbers simply to make the process of derivation easier, or is it an essential ingredient, without which it would be impossible to derive some results?   I can identify two different settings where the answer may be different:   It doesn't look like it is mandatory for results in Newtonian mechanics, General Relativity and classical electrodynamics. Can we say the same thing about quantum mechanics either way for sure?   Could this be a difference in quantum mechanics over the classical picture? I have a little problem with the placement of my picture. I want to insert it at the end of the introduction chapter but its place is not where I want.   I think the problem become from the:  \begin{figure} ... \end{figure}   Because when I insert the picture without using \begin{figure}... the picture is at the end of the chapter as I want.   Look the picture below.