PostgreSQL 'NOT IN' and subquery

后端 未结 3 1152
我寻月下人不归
我寻月下人不归 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 04:00

    You could also use a LEFT JOIN and IS NULL condition:

    SELECT 
      mac, 
      creation_date 
    FROM 
      logs
        LEFT JOIN consols ON logs.mac = consols.mac
    WHERE 
      logs_type_id=11
    AND
      consols.mac IS NULL;
    

    An index on the "mac" columns might improve performance.

提交回复
热议问题