现有两个表 A、B ,且都有相同的字段 user ,为varchar ;
现把属于表A 但不属于表B字段 user 里的值取出来。我写的代码如下:
select user from A,B where A.user not in (B.user)。
假设有个值test在表A、B中都有,那么以上语句返回的值不应该有test,但在实际执行中却把它取了出来,请问我错在什么地方呢?
现把属于表A 但不属于表B字段 user 里的值取出来。我写的代码如下:
select user from A,B where A.user not in (B.user)。
假设有个值test在表A、B中都有,那么以上语句返回的值不应该有test,但在实际执行中却把它取了出来,请问我错在什么地方呢?
select DISTINCT c.hy_user from
huiyi_jieshou as c,huiyi_qianshou as a,sys_user as b
where a.qianshou_username not in(select hy_user from huiyi_jieshou)
--and c.hy_user=b.userno
and c.hy_id='17'
select DISTINCT c.hy_user from
huiyi_jieshou as c,huiyi_qianshou as a,sys_user as b
where a.qianshou_username <>c.hy_user
--and c.hy_user=b.userno
and c.hy_id='17'为什么会查询出来你不需要的原因是,你有点逻辑混乱, 因为你用的是连表查询. a表的确查询出了你需要的内容,但是你又和c表连接,所以又把c表中你不需要的数据连接进来了