The MySQL UPDATE statement is used to modify existing records in a table. It allows you to update one or multiple columns in a table based on specified conditions.
The basic syntax of the UPDATE statement is as follows:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
Here, table_name
is the name of the table you want to update. column1
, column2
, etc. are the columns you want to update, and value1
, value2
, etc. are the new values you want to set for those columns.
The WHERE
clause is optional, but if included, it specifies the conditions that must be met for the update to occur. If no WHERE
clause is specified, all records in the table will be updated.
For example, let's say we have a table called employees
with columns id
, name
, and salary
. We want to update the salary of an employee with id
1 to $5000. The SQL statement would be:
UPDATE employees
SET salary = 5000
WHERE id = 1;
The MySQL SELECT statement is used to retrieve data from one or more tables in a database. It allows you to specify the columns you want to retrieve, as well as any conditions or sorting requirements.
The basic syntax of the SELECT statement is as follows:
SELECT column1, column2, ...
FROM table_name
WHERE condition
ORDER BY column_name;
Here, column1
, column2
, etc. are the columns you want to retrieve from the table. table_name
is the name of the table you want to select data from.
The WHERE
clause is optional, but if included, it specifies the conditions that must be met for a row to be included in the result set. If no WHERE
clause is specified, all rows in the table will be included.
The ORDER BY
clause is also optional, but if included, it specifies the column(s) you want to sort the result set by.
For example, let's say we have a table called employees
with columns id
, name
, and salary
. We want to retrieve the names and salaries of all employees whose salary is greater than $5000, sorted in descending order by salary. The SQL statement would be:
SELECT name, salary
FROM employees
WHERE salary > 5000
ORDER BY salary DESC;
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站