The UPDATE statement is used to modify the existing records in a table.
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHEREcondition;
UPDATE Customers
SET ContactName ='Alfred Schmidt', City='Frankfurt'
WHERE CustomerID =1;
Delete
The DELETE statement is used to delete existing records in a table.
DELETEFROM table_name WHEREcondition;
DELETEFROM Customers WHERE CustomerName='Alfreds Futterkiste';
Delete All Record
Deletefrom table_name;
SELECT TOP
The SELECT TOP clause is used to specify the number of records to return.
mysql
SELECT column_name(s)
FROM table_name
WHEREcondition
LIMIT number;
SELECT TOP 3*FROM Customers;
Min,Max
The MIN() function returns the smallest value of the selected column.
The MAX() function returns the largest value of the selected column.
selectMIN(column_name)
FROM table_name
WHEREcondition;
SELECTMAX(column_name)
FROM table_name
WHEREcondition;
COUNT,AVG,SUM
The COUNT() function returns the number of rows that matches a specified criterion.
SELECTCOUNT(column_name)
FROM table_name
WHEREcondition;
The AVG() function returns the average value of a numeric column
SELECTAVG(column_name)
FROM table_name
WHEREcondition;
The SUM() function returns the total sum of a numeric column.
SELECTSUM(column_name)
FROM table_name
WHEREcondition;
LIKE
SELECT column1, column2, ...
FROM table_name
WHERE columnN LIKEpattern;
Operator
Description
a%
start with a
%a
end with a
%or%
have or
_r%
str(second)==r
a_%
start with "a" and are at least 2 characters in length
a__%
start with "a" and are at least 3 characters in length
a%o
start with a,end with o
SELECT*FROM Customers
WHERE CustomerName LIKE'a%';
IN
The IN operator allows you to specify multiple values in a WHERE clause.
The IN operator is a shorthand for multiple OR conditions.
SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1, value2, ...);
SELECT column_name(s)
FROM table_name
WHERE column_name IN (SELECT STATEMENT);
BETWEEN
The BETWEEN operator selects values within a given range. The values can be numbers, text, or dates.
The BETWEEN operator is inclusive: begin and end values are included.
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
Aliases
SQL aliases are used to give a table, or a column in a table, a temporary name.
Aliases are often used to make column names more readable.
An alias only exists for the duration of that query.
An alias is created with the AS keyword.
SELECT column_name AS alias_name
FROM table_name;
SELECT column_name(s)
FROM table_name AS alias_name;
JOIN
A JOIN clause is used to combine rows from two or more tables, based on a related column between them.
INNER JOIN
The INNER JOIN keyword selects records that have matching values in both tables.
SELECT column_name(s)
FROM table1
INNERJOIN table2
ON table1.column_name = table2.column_name;
Left JOIN
The LEFT JOIN keyword returns all records from the left table (table1), and the matching records from the right table (table2). The result is 0 records from the right side, if there is no match.
Note: The LEFT JOIN keyword returns all records from the left table (Customers), even if there are no matches in the right table (Orders).
SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
LEFTJOIN Orders ON Customers.CustomerID = Orders.CustomerID
ORDERBY Customers.CustomerName;
Right Join
The RIGHT JOIN keyword returns all records from the right table (table2), and the matching records from the left table (table1). The result is 0 records from the left side, if there is no match.
SELECT column_name(s)
FROM table1
RIGHTJOIN table2
ON table1.column_name = table2.column_name;
Full join
The FULL OUTER JOIN keyword returns all records when there is a match in left (table1) or right (table2) table records.
Tip: FULL OUTER JOIN and FULL JOIN are the same.
Union
UNION 操作符用于合并两个或多个 SELECT 语句的结果集。
UNION 内部的 SELECT 语句必须拥有相同数量的列。列也必须拥有相似的数据类型。同时,每条 SELECT 语句中的列的顺序必须相同。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构