`

mysql查询怪异问题

阅读更多

由于对数据库研究不是很深,最近在使用mysql时出现如下现象,做此笔记:
有test1 , test2 ,test3 三个表,表结构相同,分别有t1,t2两列,
数据如下:
   test1
    t1     t2
=========================================
    a      a1
    b      b1
    c      c1
==========================================
   test2
   t1      t2
=========================================
   a       a2
   b       b2
   c       c2
==============================================
   test3
   t1      t2
============================================
   a      a3
   b      b3
   c      c3
============================================

执行如下查询:
查询1:
  select a.* , b.* from test1 a , test2 b
结果是test1,test2两表做笛卡尔乘绩,结果为:
test1.t1 test1.t2 test2.t1 test2.t2
a                  a1                  a                  a2
b                  b1                  a                  a2
c                  c1                  a                  a2
a                  a1                  b                  b2
b                  b1                  b                  b2
c                  c1                  b                  b2
a                  a1                  c                  c2
b                  b1                  c                  c2
c                  c1                  c                  c2

查询2:
select a.*,b.*,c.*  from test1 a , test2 b,test3 c  where a.t1 =b.t1=c.t1 order by a.t1,b.t1
结果如下:
test1.t1           test1.t2           test2.t1            test2.t2           test3.t1        test3.t2
a                  a1                  b                  b2                  a                  a3
a                  a1                  b                  b2                  b                  b3
a                  a1                  b                  b2                  c                  c3
a                  a1                  c                  c2                  a                  a3
a                  a1                  c                  c2                  b                  b3
a                  a1                  c                  c2                  c                  c3
b                  b1                  a                  a2                  a                  a3
b                  b1                  a                  a2                  b                  b3
b                  b1                  a                  a2                  c                  c3
b                  b1                  c                  c2                  a                  a3
b                  b1                  c                  c2                  b                  b3
b                  b1                  c                  c2                  c                  c3
c                  c1                  a                  a2                  a                  a3
c                  c1                  a                  a2                  b                  b3
c                  c1                  a                  a2                  c                  c3
c                  c1                  b                  b2                  a                  a3
c                  c1                  b                  b2                  b                  b3
c                  c1                  b                  b2                  c                  c3
查询3:
select a.*,b.*,c.*  from test1 a , test2 b,test3 c  where a.t1 =b.t1 and  b.t1=c.t1
结果如下:
test1.t1         test1.t2           test2.t1                       test2.t2          test3.t1          test3.t2
a                  a1                  a                  a2                  a                  a3
b                  b1                  b                  b2                  b                  b3
c                  c1                  c                  c2                  c                  c3


上述三个查询,第一和第三个好理解。但第二个就有点不知所云了,mysql中做连等是不行的。具体原因等待高手来解决了。
分享到:
评论

相关推荐

    RoboticsSignIn:[PHPMySQL] B [Ar] low Rob [Au] tics登录系统

    机器人登录页面 设置 或多或少地简单易用,即插即用。 您需要的是一个MySQL数据库,一个带有PHP的Apache服务器,然后您需要对某些.php...由于设置怪异(?我很懒并且不了解PHP?),您可能需要在上托管它。 对不起。

    oddness-community:怪异社区

    3. **数据库**:MySQL、PostgreSQL或NoSQL数据库(如MongoDB)可能用于存储用户信息、帖子、评论等数据。 4. **API集成**:社区可能与其他服务(如社交媒体登录、支付平台、分析工具)通过API进行集成。 5. **安全...

    PHP架构师 指南 设计

    - **论坛**: 优化数据库查询、使用缓存减少数据库访问。 - **新闻系统**: 静态化处理、CDN加速。 - **SNS**: 分布式架构、数据分片。 **相册类应用实现** - **多文件上传**: 使用HTML5多文件上传API。 - **图片...

    基于PHP的读怪小说连载系统源码.zip

    【描述】中的"基于PHP的读怪小说连载系统源码.zip" 提示我们,这是一个专为阅读和发布怪异题材小说设计的在线平台。源码是程序的原始代码,使用者可以通过理解并修改源码来定制自己的小说网站。这个系统可能采用了...

    1000道互联网大厂Java工程师面试题.pdf

    面试中,MyBatis的优缺点、与Hibernate的对比,#{}和${}的区别,动态SQL的使用,以及XML映射文件的标签和映射方式等都是常见问题。例如,#{}用于预编译处理,${}则是在SQL拼接时直接替换,而MyBatis的动态SQL主要...

Global site tag (gtag.js) - Google Analytics