home.social

#sqltips — Public Fediverse posts

Live and recent posts from across the Fediverse tagged #sqltips, aggregated by home.social.

  1. Check out these 2 queries:

    Query 1:

    SELECT ...
    FROM t1
    JOIN t2 ON t1.id IN (t2.id1, t2.id2);

    Query 2:

    SELECT ...
    FROM t1
    JOIN t2 ON t1.id = t2.id1
    UNION
    SELECT ...
    FROM t1
    JOIN t2 ON t1.id = t2.id2;

    They both return the same data but since most database engines struggle with OR joins, the latter will outperform the former by at least an order of magnitude.