select score from student,sc where score in (select score from student,sc where c=1 and student.s=sc.s);
36 rows in set (0.00 sec)
select score from sc;
21 rows in set (0.00 sec)
只有sc表里面有score字段,不明白为什么加点东西进去,就多了一些重复的记录了。
| score | | score |
+-------+
| 56 |
| 79 |
| 91 |
| 56 |
| 46 |
| 35 |
| 56 |
| 79 |
| 91 |
| 56 |
| 46 |
| 35 |
| 56 |
| 79 |
| 91 |
| 56 |
| 46 |
| 35 |
| 56 |
| 79 |
| 91 |
| 56 |
| 46 |
| 35 |
| 56 |
| 79 |
| 91 |
| 56 |
| 46 |
| 35 |
| 56 |
| 79 |
| 91 |
| 56 |
| 46 |
| 35 |
+-------+
+-------+
| 56 |
| 78 |
| 67 |
| 58 |
| 79 |
| 81 |
| 92 |
| 68 |
| 91 |
| 47 |
| 88 |
| 56 |
| 88 |
| 90 |
| 93 |
| 46 |
| 78 |
| 53 |
| 35 |
| 68 |
| 71 |
+-------+
select score from student,sc where score in (select score from student,sc where c=1 and student.s=sc.s);
这个sql就不正确。。。。
看最外层的sql“select score from student,sc where score in ...” student,sc表没有通过字段关联上,但你只查询了score一个字段,所以你只觉得是有一条重复的记录。
你执行“select * from student,sc where score in ...”这条sql就可以看出问题来了。
“student.s=sc.s);student,sc表没有通过字段关联上,“我也是醉了。