FROM TEN_BANG
WHERE [DIEU_KIEN1] AND [DIEU_KIEN2].AND [DIEU_KIENN];
Example of AND:
In this example we will take ID, TEN and LUONG from the NHANVIEN table, filtering employees with higher wages than 2000 and age less than 29.
This is NHANVIEN table:
The statement will look like this:
SQL> SELECT ID, TEN, LUONG FROM NHANVIEN WHERE LUONG > 2000 AND TUOI < 29;
The result will look like this:
The OR operator is used to combine multiple conditions in the WHERE clause of the SQL statement. When using OR in WHERE in conjunction with SELECT, the retrieved data only needs to satisfy one of the listed conditions. Did you notice the difference between OR and AND?
Syntax of OR:
SELECT cot1, cot2, cotN
FROM TEN_BANG
WHERE [DIEU_KIEN1] OR [DIEU_KIEN2].OR [DIEU_KIENN]
You can combine N conditions using OR, and only one of these N conditions is correct, the data will be retrieved.
Example of OR:
We will take the ID, TEN and LUONG from the NHANVIEN table below, provided that LUONG is over 6500 and less than 24 years old.
The statement will be:
SQL> SELECT ID, TEN, LUONG FROM NHANVIEN WHERE LUONG > 6500 OR age < 24;
When executing the above command, any record that satisfies the wage conditions higher than 6500 or less than 24 years will be returned in the results table, as shown below:
Now, are you confident to use the AND and OR operators in the WHERE clause? It's quite simple, isn't it?
In the next article, we will learn about a very important command in SQL, which is the UPDATE command.
Next lesson: UPDATE command in SQL
Previous article: WHERE clause in SQL