[ { INNER JOIN
| LEFT OUTER JOIN
| RIGHT OUTER JOIN
| FULL OUTER JOIN } bang2
ON bang1.cot1 = bang2.cot1 ]
bang1 and bang2 - tables used in SQL statements. Two linked tables according to the principle of state1.cot1 = bang2.cot1.
Note
Example - 1 table
SELECT *
FROM nhanvien
WHERE ten = 'Jane;
This example uses the FROM clause to get the table of nhanvien
, no other connection tables.
Example - 2 tables with INNER JOIN
SELECT nhacungcap.nhacungcap_id, nhacungcap.nhacungcap_ten, donhang.donhang_ngay
FROM nhacungcap
INNER JOIN donhang
ON nhacungcap.nhacungcap_id = donhang.nhacungcap_id;
In this example, the FROM
clause gives 2 tables and donhang
, connecting these two tables with INNER JOIN
with nhacungcap_id
column on both tables.
Example - 2 tables with OUTER JOIN
SELECT nhanvien.nhanvien_id, danhba.ho
FROM nhanvien
LEFT OUTER JOIN danhba
ON nhanvien.nhanvien_id = danhba.danhba_id
WHERE nhanvien.ten = 'Sarah';
This FROM clause gives two tables, nhanvien
and danhba
, using LEFT OUTER JOIN to connect with nhanvien_id
column in both tables.
Previous article: SELECT command in SQL Server
Next lesson: Comparison operators in SQL Server