三表MySQL关系查询

时间:2015-09-30 22:03:50

标签: mysql sql

如果我有三个简单的表格:

的MySQL>从客户中选择*;

+----+--------+  
| ID | NAME   |  
+----+--------+  
|  1 | Joey   |  
|  2 | Mike   |  
|  3 | Kellie |  
+----+--------+  
3 rows in set (0.00 sec)

的MySQL>从水果中选择*;

+----+---------+  
| ID | NAME    |  
+----+---------+  
|  1 | Apples  |  
|  2 | Grapes  |  
|  3 | Oranges |   
|  4 | Kiwis   |  
+----+---------+  
4 rows in set (0.00 sec)  

的MySQL>从购买中选择*;

+----+---------+----------+  
| ID | CUST_ID | FRUIT_ID |  
+----+---------+----------+----  
|  2 |       3 |  2       |  
|  3 |       1 |  4       |  
|  4 |       1 |  2       |  
|  5 |       2 |  1       |      
+----+---------+----------+----    

如何选择Joey尚未购买的水果?谢谢你的帮助。 - 理查德

0 个答案:

没有答案