两个表
 T_product 中 有 字段 productid  productname
 T_staffproduct 中 有字段 productid staffid现在我要查询出 T_product 中 的 productid  productname条件是  T_product 中  字段 productid  等于  T_staffproduct 中 字段 productid 但是 T_staffproduct 中 字段 productid 有条件的  只能是 select T_staffproduct.productid from T_staffproduct where staffid =X的不知道说明白了没

解决方案 »

  1.   


    select a.productid,a.productname from T_product a join T_staffproduct b on a.productid=b.productid
      where staffid =X
      

  2.   

    SELECT T.* FROM T_product T ,T_staffproduct T1 
    WHERE T.productid  =T1.productid   AND T1.staffid ='X'
      

  3.   


    select * from t_product a 
                where  exists (select 1 from t_staffproduct b where staffid='x' and a.productid=b.productid)
      

  4.   

    select a.productid,a.productname from T_product a inner join T_staffproduct b on a.productid=b.productid
      where staffid =Xselect a.productid,a.productname from T_product a,T_staffproduct b    
    where a.productid=b.productid
      and staffid =X两个是一样的!
      

  5.   

    lz可以试下这个语句,应该可以解决这个问题的~~~~~~select a.productid,a.productname from T_product as a inner join T_staffproduct as b on a.a.productid=b.productid and b.productid in (select T_staffproduct.productid from T_staffproduct where staffid =X)
      

  6.   

    select * from t_product a 
                where  exists (select 1 from t_staffproduct b where staffid='x' and a.productid=b.productid)这个更好,少于IN,IN太慢