FROM nhanvien
WHERE ten =
'Jane'; In the WHERE clause above, we filter out the results from the table. The SELECT statement returns rows from the table named Jane. Since using * in the SELECT statement, all fields in the table will appear in the result set.
For example - using AND conditions
SELECT *
FROM nhanvien
WHERE ho = 'Anderson'
AND nhanvien_id >= 3
000;
The above clause uses two conditions with the AND keyword. The SELECT statement above will return the employees whose last name is Anderson and have a number greater than or equal to 3000.
For example - use an OR condition
SELECT nhanvien_id, ho, ten
FROM nhanvien
WHERE ho = 'Johnson'
OR ten = 'Danielle';
In this example, the SELECT statement returns the following values: the ID of the employee, the first and last name from the last table with the last name Johnson or the name Danielle.
Example - combine conditions AND and OR
SELECT *
From nhanvien
WHERE (bang = 'California' AND ho = 'Smith')
OR (nhanv
ien_id = 82);
The above example results in employees living in California and having the surname Smith or having the same name as 82. Parentheses are used to determine the order in which each condition is executed (as in math).
Example - table combination
SELECT nhanvien.nhanvien_id,danhba.ho
FROM nhanvien
INNER JOIN danhba
ON nhanvien.nhanvien_id = danhba.danhba_id
WHERE nhanvien.tan = 'Sarah';
The SELECT statement above will return the rows named in the table as Sarah. The table of names and names is connected by the user_id in the table and the list in the list.
Previous article: Comparison operators in SQL Server
Next lesson: SQL ORDER BY clause