MariaDB FROM 关键字用于指定应从中选择或删除数据的表。
示例:
考虑一个数据库表名为Employee,具有以下记录:
EmpID | Name | City | Age | Salary |
---|---|---|---|---|
1 | John | London | 25 | 3000 |
2 | Marry | New York | 24 | 2750 |
3 | Jo | Paris | 27 | 2800 |
4 | Kim | Amsterdam | 30 | 3100 |
5 | Ramesh | New Delhi | 28 | 3000 |
6 | Huang | Beijing | 28 | 2800 |
选择Name和
SELECT Name, Salary FROM Employee;
这将产生如图所示的结果如下:
Name | Salary |
---|---|
John | 3000 |
Marry | 2750 |
Jo | 2800 |
Kim | 3100 |
Ramesh | 3000 |
Huang | 2800 |
要选择 Employee 表的所有字段,查询将为:
SELECT * FROM Employee;
以下代码的结果将是:
EmpID | Name | City | Age | Salary |
---|---|---|---|---|
1 | John | London | 25 | 3000 |
2 | Marry | New York | 24 | 2750 |
3 | Jo | Paris | 27 | 2800 |
4 | Kim | Amsterdam | 30 | 3100 |
5 | Ramesh | New Delhi | 28 | 3000 |
6 | Huang | Beijing | 28 | 2800 |
要删除 EmpID 为 5 的员工的记录,查询将是:
DELETE FROM Employee
WHERE EmpID = 5;
-- 查看结果
SELECT * FROM Employee
现在Employee表将包含以下记录:
EmpID | Name | City | Age | Salary |
---|---|---|---|---|
1 | John | London | 25 | 3000 |
2 | Marry | New York | 24 | 2750 |
3 | Jo | Paris | 27 | 2800 |
4 | Kim | Amsterdam | 30 | 3100 |
6 | Huang | Beijing | 28 | 2800 |
同样,删除员工的记录其中 city 以"New"开头,查询将为:
DELETE FROM Employee
WHERE City LIKE 'New%';
-- 查看结果
SELECT * from Employee;
现在 Employee 表将包含以下记录:
EmpID | Name | City | Age | Salary |
---|---|---|---|---|
1 | John | London | 25 | 3000 |
3 | Jo | Paris | 27 | 2800 |
4 | Kim | Amsterdam | 30 | 3100 |
6 | Huang | Beijing | 28 | 2800 |