number1killer 2017-09-01 10:34 采纳率: 0%
浏览 704

mysql查询结果错误问题--增加了一些重复的记录

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 |
+-------+

  • 写回答

2条回答

  • 蜗牛_snail 2017-09-02 00:29
    关注

    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就可以看出问题来了。

    评论

报告相同问题?

悬赏问题

  • ¥15 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!