TABLE OPERATION
SQL Aliases
▰ TABLE ALIASES
▻ We are about to select data from more than one table, table aliases willbe
helpful.
▻ Table aliases created in the same way ascolumn aliases.
▰ Example OR
SELECT nim AS nomor_induk SELECT nimnomor_induk
5
Outline
▰ Inner Join
▻ Cartesian Join/Product
▻ Equijoin
▻ Non-equijoin
▻ Natural Join
6
CARTESIAN JOIN
▰ QUERY:
SELECT t.toy, b.boy
FROM toys t
CROSS JOIN
Boys b
The CROSS JOIN returns every row fromone
table crossed with every row from the
second
The join above will return 20 results to
account for every possible combination 8
Try this your self
9
When to use it?
11
Inner Join: Equijoin
14
JOIN- Summary??
15
Costumer
order
2
Outer JOIN
17
Outline
▰ Outer joins
▻ Left outer joins
▻ Right outer joins
18
Outer Join
▰ An outer joins
returns all rows
from one of the
tables, along
with matching
information
from another
table.
▰ Review of
Equijoin
19
Outer Join (Cont.)
20
Left Outer Join
▰ Example:
SELECT g.girl,t.toy
FROM girls g
LEFT OUTER JOIN toyst
On g.toy_id = t.toy_id
Result
21
Seems like INNER JOIN?
22
Seems like INNER JOIN? (Cont.)
23
Right Outer Join
▰ The right outer join evaluates the right table against the left table
▰ Result:
24
A join that returns both the left and right results?
25
Costumer
order
3
Self join
27
Self join
28
Self join(Cont.)
30
4
UNION
31
Union
32
Costumers
Suppliers
References
https://www.w3schools.com/