I have a table hardest
One Two
apple orange
orange grapes
banana strawberry
orange strawberry
grapes apple
Now you can see that i have listed here 5 pairs. Let me tell you that it is not an ordinary table because in this table fruits' name(apple) are sometime in column one and sometime in column two.
And another table Description
name color
apple red
orange orange
strawberry pink
banana yellow
grapes black
Suppose iam banana and i don't want to see the description of fruit which are paired with me. Now can somebody tell me how to display the details of a fruit which has pairing with all of the following in mysql but not with banana: strawberry, grapes, apples.
I am telling the way to do it which is not supported in 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
banana, citingMINUS(which MySQL does not support) as the solution in other RDBMS; there are plenty of examples on this site and others explaining how to effect an equivalent operation in MySQL: indeed, searching Google for "MySQL MINUS" brings up plenty of good results. Have you had a go at implementing one of these solutions yourself? Let us know if you encounter any problems.