在我的 postgres 数据库上:
当我做
SELECT* FROM ETIQUETTES WHERE DO_PIECE='BL7591'
我有
...|do_piece|ar_ref |...
---------------------------
...|BL7591 |40L.PA.NAT|...
---------------------------
...|BL7591 |37LL.POM. |...
当我做
SELECT* FROM F_DOCLIGNE WHERE DO_PIECE='BL7591'
我有
...|do_piece|ar_ref |...
---------------------------
...|BL7591 |46L-E.PA.N|...
---------------------------
...|BL7591 |37LL.POM. |...
然后当我用 IN 做我的请求时
SELECT* FROM ETIQUETTES AS a WHERE DO_PIECE='BL7591' AND a.AR_REF IN (SELECT AR_REF FROM F_DOCLIGNE WHERE DO_PIECE='BL7591')
我已经预料到了
...|do_piece|ar_ref |...
---------------------------
...|BL7591 |37LL.POM. |...
但是当我用 NOT IN 提出请求时
SELECT* FROM ETIQUETTES AS a WHERE DO_PIECE='BL7591' AND a.AR_REF NOT IN (SELECT AR_REF FROM F_DOCLIGNE WHERE DO_PIECE='BL7591')
我一无所有
...|do_piece|ar_ref |...
---------------------------
代替
...|do_piece|ar_ref |...
---------------------------
...|BL7591 |40L.PA.NAT|...
我已经尝试过 NOT EXIST 或 LEFT JOIN / NULL 但结果总是一样的......我不明白为什么以及如何得到好的结果......你能帮我理解我的错误吗?