PostgreSQL: NOT IN versus EXCEPT performance difference (edited #2)

Query #1 is not the elegant way for doing this… (NOT) IN SELECT is fine for a few entries, but it can’t use indexes (Seq Scan).

Not having EXCEPT, the alternative is to use a JOIN (HASH JOIN):

    SELECT sp.id
    FROM subsource_position AS sp
        LEFT JOIN subsource AS s ON (s.position_id = sp.id)
    WHERE
        s.position_id IS NULL

EXCEPT appeared in Postgres long time ago… But using MySQL I believe this is still the only way, using indexes, to achieve this.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)