Professional Documents
Culture Documents
JOIN
JOIN
mySQL
join.pptx Trang 1 / 10
join.pptx Trang 2 / 10
join.pptx Trang 3 / 10
The relationship between the two tables is specified by the
customer_id key . It is the "primary key" in customer table and
the "foreign key" in order table.
join.pptx Trang 4 / 10
The relationship between the two tables is specified by the
customer_id key . It is the "primary key" in customer table and
the "foreign key" in order table.
join.pptx Trang 5 / 10
Inner Join
SELECT firstname, lastname, amount, c.CI
FROM customer c
INNER JOIN order o
ON c.CI= o.CI
join.pptx Trang 6 / 10
Left join
SELECT firstname, lastname, amount, c.CI, o.CI
FROM customer c
LEFT JOIN order o
ON c.CI= o.CI
join.pptx Trang 8 / 10
Left vs Right join
• The order in which the tables are joined is important.
• Right join the customer table to the order table?
The result would be the same as left joining the order table to the
customer table
join.pptx Trang 9 / 10
Full join
SELECT firstname, lastname, amount
FROM customer c
FULL JOIN order o
ON c.CI= o.CI