私は最も難しいテーブルを持っています
One Two
apple orange
orange grapes
banana strawberry
orange strawberry
grapes apple
これで、ここに5つのペアがリストされていることがわかります。このテーブルでは、果物の名前(リンゴ)が1列目にある場合と、2列目にある場合があるため、通常のテーブルではありません。
And another table Description
name color
apple red
orange orange
strawberry pink
banana yellow
grapes black
iamバナナと私がペアになっている果物の説明を見たくないとしましょう。 さて、誰かがmysqlで次のすべてとペアになっているが、バナナとはペアになっていない果物の詳細を表示する方法を教えてもらえます:イチゴ、ブドウ、リンゴ。
私はmysqlでサポートされていないそれを行う方法を教えています。
Select * from description
natural join (select one as name where two='apple' union select two as name where one='apple') as t1
natural join (select one as name where two='grapes' union select two as name where one='grapes') as t2
natural join (select one as name where two='strawberry' union select two as name where one='strawberry') as t3
MINUS
Select * from description
natural join (select one as name where two='banana' union select two as name where one='banana') as b6