What is a full join? How is it different from other joins?
A "FULL JOIN" is an outer join that takes *all* data from both tables, matched where it can, as opposed to a LEFT or RIGHT join that takes all the data from one table, *and* any matching records from the other table,
Examples:
CUSTOMER table contains details of customers
DISCOUNTDEAL table contains details of different discount deals
You want to see all customers, and list the discount deal they have if they have one:
SELECT *
FROM CUSTOMER
LEFT JOIN DISCOUNTDEAL ON CUSTOMER.DEALID=DISCOUNTDEAL.D EALID
You want to see all deals, and list the customers that have that deal if there are any:
SELECT *
FROM CUSTOMER
RIGHT JOIN DISCOUNTDEAL ON CUSTOMER.DEALID=DISCOUNTDEAL.D EALID
(you could also do a LEFT JOIN from DISCOUNTDEAL to CUSTOMER to achieve the same thing, of course)
You want to see all deals (even it no customers are using them), and all customers (even if they don't have a deal)
SELECT *
FROM CUSTOMER
FULL OUTER JOIN DISCOUNTDEAL ON CUSTOMER.DEALID=DISCOUNTDEAL.D EALID
Examples:
CUSTOMER table contains details of customers
DISCOUNTDEAL table contains details of different discount deals
You want to see all customers, and list the discount deal they have if they have one:
SELECT *
FROM CUSTOMER
LEFT JOIN DISCOUNTDEAL ON CUSTOMER.DEALID=DISCOUNTDEAL.D EALID
You want to see all deals, and list the customers that have that deal if there are any:
SELECT *
FROM CUSTOMER
RIGHT JOIN DISCOUNTDEAL ON CUSTOMER.DEALID=DISCOUNTDEAL.D EALID
(you could also do a LEFT JOIN from DISCOUNTDEAL to CUSTOMER to achieve the same thing, of course)
You want to see all deals (even it no customers are using them), and all customers (even if they don't have a deal)
SELECT *
FROM CUSTOMER
FULL OUTER JOIN DISCOUNTDEAL ON CUSTOMER.DEALID=DISCOUNTDEAL.D EALID