Cross & Natural Joins

Cross Join

-- every row in the left table will match with every row 
-- in the right table in cross join

select *
from left_product
         cross join right_product;

 product_id | product_name | product_id | product_name 
------------+--------------+------------+--------------
          1 | a            |          1 | a
          1 | a            |          2 | B
          1 | a            |          3 | C
          1 | a            |          4 | d
          1 | a            |          7 | E1
          2 | B            |          1 | a
          2 | B            |          2 | B
          2 | B            |          3 | C
          2 | B            |          4 | d
          2 | B            |          7 | E1
          3 | C            |          1 | a
          3 | C            |          2 | B
          3 | C            |          3 | C
          3 | C            |          4 | d
          3 | C            |          7 | E1
          5 | E            |          1 | a
          5 | E            |          2 | B
          5 | E            |          3 | C
          5 | E            |          4 | d
          5 | E            |          7 | E1


-- short hand notation for cross join
select * from left_product , right_product;
-- same output as above

-- using inner join to preform query like cross join
-- using ON TRUE at the end
select *
from left_product
         inner join right_product on true;
-- same output as above

Natural Join

Loading sample data

Queries

Last updated

Was this helpful?