PostgreSQL 'NOT IN' and subquery

后端 未结 3 1156
我寻月下人不归
我寻月下人不归 2020-12-13 03:14

I\'m trying to execute this query:

SELECT mac, creation_date 
FROM logs 
WHERE logs_type_id=11
AND mac NOT IN (select consols.mac from consols)
3条回答
  •  孤城傲影
    2020-12-13 03:45

    When using NOT IN, you should also consider NOT EXISTS, which handles the null cases silently. See also PostgreSQL Wiki

    SELECT mac, creation_date 
    FROM logs lo
    WHERE logs_type_id=11
    AND NOT EXISTS (
      SELECT *
      FROM consols nx
      WHERE nx.mac = lo.mac
      );
    

提交回复
热议问题