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中做连等是不行的。具体原因等待高手来解决了。

你可能感兴趣的:(数据结构,C++,c,mysql,C#)