I have a table like this...  ========================================================================== UID    ||      PARENT ID           ||  SPONSOR ID ========================================================================== 1      ||         0                ||     0 2      ||         1                ||     1 3      ||         1                ||     1 4      ||         2                ||     1 5      ||         2                ||     2 6      ||         4                ||     1 7      ||         0                ||     0 8      ||         7                ||     7   Lets say I am a user with UID = 1, now I want to query so I can get all of my nodes inside my network, how to query this table so I can get this result:  ============================================================================ UID     ||        PARENT ID          || SPONSOR ============================================================================ 2       ||          1                || 1 3       ||          1                || 1 4       ||          2                || 1 5       ||          2                || 2 6       ||          4                || 1          I try to using this query   select @pv:=uid as uid, parentid,sponsorid from genealogy  join (select @pv:=1)tmp where parentid=@pv   But the result is only  ============================================================================ UID     ||        PARENT ID          || SPONSOR ============================================================================ 2       ||          1                || 1 4       ||          2                || 1 6       ||          4                || 1   Whats wrong with my query.. anyone can help me? Thankyou very much
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);
What is the CVE-2014-6271 bash vulnerability (Shellshock) and how do I fix it? Recently, there have been news going around regarding "CVE-2014-6271" (See ), which is a vulnerability in Bash. How do I know if I am affected by this, how can I fix it, and why should I care?  This is designed as a canonical answer for this vulnerability, due to its scope and severity. Hide a Subdomain from Google/Search Engine SEO Result? What are the barriers to understanding pointers and what can be done to overcome them? Why are pointers such a leading factor of confusion for many new, and even old, college level students in C or C++?  Are there any tools or thought processes that helped you understand how pointers work at the variable, function, and beyond level?  What are some good practice things that can be done to bring somebody to the level of, "Ah-hah, I got it," without getting them bogged down in the overall concept? Basically, drill like scenarios. My recipe for hummus says to cook the garbanzo beans with a little baking soda to soften them. Does this work with other legumes?   I've often seen the advice against salting the cooking water for beans, as it supposedly toughens them. Will a different sodium compound, bicarbonate, have the opposite effect?   Would love to know the science of this issue. What does "Could not find or load main class" mean? Parse HTML in Android Boot failure : No DEFAULT or UI configuration directive found! What's the appropriate reaction to an answer that doesn't attribute the source it's copied from? I am trying to understand how to see the total size of my hard drive &amp; how much is left. It was recommended on various searches to use the command below   df -h Filesystem      Size  Used Avail Use% Mounted on udev            7.8G     0  7.8G   0% /dev tmpfs           1.6G  9.6M  1.6G   1% /run /dev/sda1       219G   29G  180G  14% / tmpfs           7.8G   18M  7.8G   1% /dev/shm tmpfs           5.0M  4.0K  5.0M   1% /run/lock tmpfs           7.8G     0  7.8G   0% /sys/fs/cgroup cgmfs           100K     0  100K   0% /run/cgmanager/fs tmpfs           1.6G   64K  1.6G   1% /run/user/1000   However I don't understand any of these directories. I mean what are they, are these all directories or partitions or what? And why do they appear under "mounted on"? How does that bit work. I assume the /dev/sda1 is my solid state drive? So now if I install applications, which one of these directories does my software get installed  into? I assume it just gets installs in the / directory (I haven't even got a clue what the / directory is). Can someone explain what the other directories are and what they are used for? I see stuff like command 1&gt; out or with 2&gt;&amp;1 to redirect stderr, but sometimes I also see &amp;&gt; by itself, etc.  What is the best way to understand &amp; and what it means exactly? What do parentheses surrounding an object/function/class declaration mean? I'm new to both JavaScript and . In YUI library examples, you can find many uses of this construct:  (function() {     var Dom = YAHOO.util.Dom,     Event = YAHOO.util.Event,     layout = null,         ... })();   I think the last couple of parentheses are to execute the function just after the declaration.  ... But what about the previous set of parentheses surrounding the function declaration?  I think it is a matter of scope; that's to hide inside variables to outside functions and possibly global objects. Is it? More generally, what are the mechanics of those parentheses? How can I maximize the "blurry background, sharp subject" (bokeh) effect? I used exposure compensation when I take my shots and adjust it whenever it needs adjustments. Most of the time I shoot using Manual mode.  My problem is, when I'm out on a sunny day I can't judge whether my shot is overexposed or underexposed because the sun is too bright. Sometimes when I checked my viewfinder the image looks perfectly exposed to my eyes, but when I check it on my computer when I get home the images looks underexposed or overexposed. I tried to judge my shot's exposure using histogram, but still having a hard time. The only thing I understand about the histogram is that, the right side is the highlights and the left side is the shadow.  How do you judge whether the shot is overexposed or underexposed when you are out on a sunny day? Capitalize fields of study? Was the singularity at Big Bang perfectly uniform and if so, why did the universe lose its uniformity? Remove only the commas present within the double quotes In a text file, I want to remove , (commas) and also the " (quotes) (only if the double quotes  contains  numbers separated by commas).  56,72,"12,34,54",x,y,"foo,a,b,bar"   Expected ouput  56,72,123454,x,y,"foo,a,b,bar"   Note: I show the above line just as an example. My text file contains many lines like above and the numbers separated by commas present within the double quotes should vary. That is,  56,72,"12,34,54",x,y,"foo,a,b,bar" 56,92,"12,34",x,y,"foo,a,b,bar" 56,72,"12,34,54,78,76,54,67",x,y,"foo,a,b,bar" 56,72,x,y,"foo,a,b,bar","12,34,54" 56,72,x,y,"foo,a,b,bar","12,34,54","45,57,84,92","bar,foo"   Expected output:  56,72,123454,x,y,"foo,a,b,bar" 56,92,1234,x,y,"foo,a,b,bar" 56,72,12345478765467,x,y,"foo,a,b,bar" 56,72,x,y,"foo,a,b,bar",123454 56,72,x,y,"foo,a,b,bar",123454,45578492,"bar,foo"   There a n number of numbers present within the double quotes separated by commas. And also leave the double quotes which contains characters as it is.  I love sed text processing tool. I'm happy if you post any sed solution for this. Why is time special? In Special Relativity, the spacetime interval between two events is $s^2 = -(c{\Delta}t)^2+({\Delta}x)^2+({\Delta}y)^2+({\Delta}z)^2$ giving the Minkowski metric $\eta_{\mu\nu}=\text{diag}(-1, 1, 1, 1)$. What is the justification for making time have a negative coefficient, and how closely is that related to the 2nd law of thermodynamics? Sure, by letting $\eta = \text{diag}(1, 1, 1, 1)$, we get a pretty boring spacetime, and the boosts in the Poincaré group become trig instead of hyperbolic functions, but what's the physical reasoning behind this? US Salary Transfered to Indian Acc and Tax Relation I am on an H1b visa working and receiving a salary in the US. I have transferred approximately $15-20k to my account in India Account (not an NRE account).    How would this transfer affect my taxes in US and India. How can I avoid tax on the money that I have transferred. Would any investments help save taxes? Do I need to declare anything? If so, where ? Show that any prime ideal from such a ring is maximal. Let R be a commutative ring with an identity such that for all $r\in$ R, there exists some $n&gt;1$ such that $r^n = r$. Show that any prime ideal is  maximal. (Atiyah and MacDonald, Introduction to Commutative Algebra, Chapter 1, Exercise 7.)    Any hints? How long does the new dwellers queue last? When clicking the radio room icon that attracts a new dweller to your vault, how long will they stay queued out in front of the vault for before giving up?  Or will they?  I'm at max population and would rather not kill existing dwellers to accommodate them in my vault.