我这儿有两个表的数据。第一个表里有394条数据。第二个表里有194条数据。这两个表之间有一个字段是相同的。想把这两个表连接起来。有两个查询条件是and的关系。分别是两个表的条件。不管我怎么连都少了很多数据请教高手如何连?

解决方案 »

  1.   

    select * from tb1,tb2 where tb1.id = tb2.tb1id and tb1.条件=?? and tb2.条件=??
      

  2.   

    select * from tb1 left join tb2 on tb1.XX=tb2.XX
      

  3.   

    select t1.* , t2.* from t1 , t2 where t1.关键字 = t2.关键字 and t1.条件 = ... and t2.条件 = ...
      

  4.   

    估计是and的条件导致你想要的数据跟实际的有差异呀!你可以把你的表结构,查询语句贴出来给大家看看呀
      

  5.   

    以上的查询方式我都试过了
    select a.communiquecode,max(a.commname) as commname,max(a.spec) as spec,max(isnull(b.qua,0))as qua 
    from v_bu_commcptype a left  join bu_inventorycomm b 
    on a.communiquecode=b.communiquecode where a.class in (1173,1174) and inventid=1199 group by a.communiquecode a 表里有394条数据 b表里有194条数据。我连b表的原因就是想把b表里的qua取出来。
      

  6.   

    最好给出完整的表结构,测试数据,计算方法和正确结果.否则耽搁的是你宝贵的时间。
    如果有多表,表之间如何关联?
    发帖注意事项
    http://topic.csdn.net/u/20091130/21/fb718680-98ff-4afb-98d8-cff2f8293ed5.html?24281
      

  7.   

    select communiquecode,commname,spec,qua from bu_inventorycomm where inventid=1199里面有194条数据。select class,communiquecode,commname,spec from v_bu_commcptype where class in (1173,1174)里面有394条数据我想把这两个表连起来为的是把下面这个表里的数据都取出来。然后把上面那个表里对应的qua取出来。 
      

  8.   

    select t1.* , t2.*
    from bu_inventorycomm t1 ,  v_bu_commcptype t2
    where t1.communiquecode = t2.communiquecode
    and t1.inventid=1199 and t2.class in (1173,1174)
      

  9.   

    还是不对。就100多条数据。这个查询本本上是过滤掉了qua为空的数据