请问一下我查两个表的数据时,为什么这样查table1.a=table2.b可以查出来,但查<>就不行。
例:select * from table1,table2 where table1.a<>table2.b  这个表达式会查出N多数据出来
    select * from table1,table2 where table1.a=table2.b  这个表达式可以正常查出来请高手指教。

解决方案 »

  1.   

    select   *   from   table1,table2   where   table1.a <> table2.b
    ------------------------------------------------------------
    衹要a和b不等,就滿足條件,所以交叉組合,就有N多記錄
      

  2.   

    select       *       from       table1,table2默认情况下是select a.*,b.* from table1 a cross join table2 b 的
    是交叉查询 查询出的是符合条件笛卡尔积select   *   from   table1,table2   where   table1.a <> table2.b
    对应的是
    select a.*,b.* from table1 a cross join table2 b on table1.a <> table2.b
    select   *   from   table1,table2   where   table1.a=table2.b
    对应
    select a.*,b.* from table1 a cross join table2 b on table1.a = table2.b结果当然不一样拉 
      

  3.   

    想要查出不等于的很简单:select * from table1 where table1.a  not in (select b from table2 where table1.a=table2.b)
    这样利用子查询就出来了,你的<>,数据库会进行笛卡尔乘积,形成一张笛卡尔表,这样就出现了很多匹配的项。如果我得解释合乎你的心意的话,给我分数就好,呵呵。