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 php 同步电商平台多个店铺增量订单和订单状态
  • ¥15 关于logstash转发日志时发生的部分内容丢失问题
  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。