1
各childrowには親子と位置があります。同じ位置の子どもの場合は、1行あります。start='1'
です。mysqlは不正な結果を返します
私がやっていることは、開始行で保留中の行を返すことです。
結果は次のとおりです。保留中の開始(owen)(dave、paul)。彼らは同じ位置を持っているからです。ここではそれが関心の位置だけだ場合は、where position=1
句を追加することができますSQLのフィドルhttp://sqlfiddle.com/#!2/e6e54/1
id | name | parentid| position| start | pending |
1 | mike | 0 | 0 | 0 | 0 |
2 | dave | 1 | 1 | 0 | 1 |
3 | paul | 1 | 1 | 0 | 1 |
4 | john | 1 | 2 | 1 | 0 |
5 | bret | 1 | 2 | 0 | 0 |
6 | owen | 1 | 1 | 1 | 0 |
7 | rick | 1 | 3 | 1 | 0 |
8 | jaye | 1 | 3 | 0 | 0 |
$getquery = mysql_query("select child.*
from `mytable` child inner join `mytable` parent
on parent.id=child.parentid
inner join `mytable` child2 on child.parentid=child2.parentid
and child2.pending='1'
where child.start='1' ORDER BY child.id DESC");
while($row=mysql_fetch_assoc($getquery)) {
$name = $row['name'];
echo "<p>Name: $name </p>";
}
あなたのクエリは出力に 'chid2'を使用しません。親との結合は、ルートエントリを削除するので、それを完全にスキップすることができます。 – dasblinkenlight
ああ、私は..どのように私は希望の結果を得るだろうか?保留中の行とその開始行? – user892134
なぜ、オーウェン、デイヴ、ポールだけが表示されるのですか?すべての行ではないのですか? –