mysql - 这些查询有什么区别
问题描述
问题 :
什么是差异......在这些查询中......当表是
我在这里使用了表别名我相信没有错误
------------------------ Tables -------------------
mysql> select * from college;
+----------+-------+------------+
| cName | state | enrollment |
+----------+-------+------------+
| Stanford | CA | 15000 |
| Berkeley | CA | 36000 |
| MIT | MA | 10000 |
| Cornell | NY | 21000 |
+----------+-------+------------+
4 rows in set (0.00 sec)
mysql> select * from apply;
+-----+----------+----------------+----------+
| sID | cName | major | decision |
+-----+----------+----------------+----------+
| 123 | Berkeley | CS | Y |
| 123 | Cornell | EE | Y |
| 123 | Stanford | CS | Y |
| 123 | Stanford | EE | N |
| 234 | Berkeley | biology | N |
| 345 | Cornell | bioengineering | N |
| 345 | Cornell | CS | Y |
| 345 | Cornell | EE | N |
| 345 | MIT | bioengineering | Y |
| 543 | MIT | CS | N |
| 678 | Stanford | history | Y |
| 765 | Cornell | history | N |
| 765 | Cornell | psychology | Y |
| 765 | Stanford | history | Y |
| 876 | MIT | biology | Y |
| 876 | MIT | marine biology | N |
| 876 | Stanford | CS | N |
| 987 | Berkeley | CS | Y |
| 987 | Stanford | CS | Y |
+-----+----------+----------------+----------+
19 rows in set (0.00 sec)
----------------- 2个几乎相同的查询:但不同。输出 -----------------
mysql> Select c.cname from College c,Apply a where c.cname=a.cname and enrollment > 20000 and major='CS';
+---------+
| cname |
+---------+
| Cornell |
+---------+
1 row in set (0.00 sec)
----------------------> only One row
mysql>
mysql> select college.cname from college,apply where college.cname = apply.cname and enrollment > 20000 and major = 'CS';
+----------+
| cname |
+----------+
| Berkeley |
| Cornell |
| Berkeley |
+----------+
3 rows in set (0.00 sec)
WHILE -------------------------> three rows
解决方案
你有 2 个不同的表 College 和 College,所以你得到不同的输出。如果您使用 College 而不是 College,那么您将获得相同的输出。
推荐阅读
- gradle - Gradle:在任务被链接时也运行前置和后置任务?
- python - 自定义包已安装但在另一个项目中找不到
- shell - 将数组的数据插入数据库
- react-native - Expo 是否能够在不需要 Mac 的情况下构建可用于生产的 iOS 应用程序?
- php - 如何以正确的格式序列化实体时间戳以将其与数据表一起使用?
- javascript - 对象不是在 react-sidenav 上使用 withRR4() 的函数
- excel - 特定索引匹配
- mysql - 在 C 中追加或创建文件时如何要求连续块(非碎片)?
- javascript - 在 Javascript 中将对象值打包成一个 4 字节的无符号整数
- machine-learning - 如何对数据应用交叉验证?