MariaDB 关键字

MariaDB FROM 关键字用于指定应从中选择或删除数据的表。

示例:

考虑一个数据库表名为Employee,具有以下记录:

EmpIDNameCityAgeSalary
1JohnLondon253000
2MarryNew York242750
3JoParis272800
4KimAmsterdam303100
5RameshNew Delhi283000
6HuangBeijing282800

选择Name和Salary 数据,可以使用以下查询:

SELECT Name, Salary FROM Employee; 

这将产生如图所示的结果如下:

NameSalary
John3000
Marry2750
Jo2800
Kim3100
Ramesh3000
Huang2800

要选择 Employee 表的所有字段,查询将为:

SELECT * FROM Employee; 

以下代码的结果将是:

EmpIDNameCityAgeSalary
1JohnLondon253000
2MarryNew York242750
3JoParis272800
4KimAmsterdam303100
5RameshNew Delhi283000
6HuangBeijing282800

要删除 EmpID 为 5 的员工的记录,查询将是:

DELETE FROM Employee
WHERE EmpID = 5;

-- 查看结果
SELECT * FROM Employee 

现在Employee表将包含以下记录:

EmpIDNameCityAgeSalary
1JohnLondon253000
2MarryNew York242750
3JoParis272800
4KimAmsterdam303100
6HuangBeijing282800

同样,删除员工的记录其中 city 以"New"开头,查询将为:

DELETE FROM Employee
WHERE City LIKE 'New%';

-- 查看结果
SELECT * from Employee; 

现在 Employee 表将包含以下记录:

EmpIDNameCityAgeSalary
1JohnLondon253000
3JoParis272800
4KimAmsterdam303100
6HuangBeijing282800