Search code examples
sqlsql-servert-sqljoincross-join

Is CROSS JOIN all we need?


If we got rid of INNER JOIN, LEFT JOIN. RIGHT JOIN, and FULL JOIN tomorrow, could we completely replace their functionality with CROSS JOIN and filters on it? I initially thought that we obviously could, but edge cases such as this one have given me doubts.


Solution

  • a  b
    1  1
    2  4
    

    JOIN

    1, 1
    

    LEFT JOIN

    1, 1
    2, NULL
    

    RIGHT JOIN

    1, 1
    NULL, 4
    

    FULL JOIN

    1, 1
    2, NULL
    NULL, 4
    

    CROSS JOIN

    1, 1
    1, 4
    2, 1
    2, 4
    

    How are you going get LEFT JOIN from CROSS JOIN?