FROM NHANVIEN, TIENTHUONG
WHERE NHANVIEN.ID = TIENTHUONG.NHANVIEN_ID;
The result is:
+----+----------+-----+--------+ | ID | TEN | TUOI| SOTIEN | +----+----------+-----+--------+ | 3 | Nga | 23 | 3000 | | 3 | Nga | 23 | 1500 | | 2 | Loan | 25 | 1560 | | 4 | Manh | 25 | 2060 | +----+----------+-----+--------+
You can see here that JOIN is executed in the WHERE clause. Some operators can be used to combine tables: =, <,>, <>, <=,> =,! =, BETWEEN, LIKE, and NOT. However, the most commonly used operator is the equal sign (=).
In SQL, there are several types of JOINs available:
JOIN type Meaning INNER JOIN Returns records with matching values between two tables. LEFT JOIN Returns all records from the left panel and matching records from the right panel. The result is NULL from the right side if there is no match. RIGHT JOIN Returns all records from the right panel and the appropriate records from the left panel. The result is NULL from the left side if there is no matching result. FULL JOIN Returns all records in the left table and the table must be combined. SELF JOIN Used to combine a table with itself as if the table is considered two tables, replace at least one temporary table name in the SQL statement. CARTESIAN JOIN Returns the Cartesian product of record sets from two or more combined tables.In the following articles, Quantum will discuss with you more about each of the JOIN types mentioned above. Have you remembered to it!
Previous article: Constraints in SQL
Next lesson: UNION clause in SQL