两个表
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的不知道说明白了没
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的不知道说明白了没
select a.productid,a.productname from T_product a join T_staffproduct b on a.productid=b.productid
where staffid =X
WHERE T.productid =T1.productid AND T1.staffid ='X'
select * from t_product a
where exists (select 1 from t_staffproduct b where staffid='x' and 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两个是一样的!
where exists (select 1 from t_staffproduct b where staffid='x' and a.productid=b.productid)这个更好,少于IN,IN太慢