MySQL Study Notes 7 query, modify, and delete
I. query
The basic structure of query statements. The order cannot be changed:
SELECT selection_list
FROM table_list where to select a row
WHERE primary_constraint
How does group by grouping_columns GROUP results?
HAVING secondary_constraint must meet the second condition
Order by sorting_columns how to sort results
LIMIT on LIMIT count results
Note: All keywords used must be given exactly in the above order. For example, a HAVING clause must be followed BY the group by clause and before the order by clause.
Specific Queries include multi-condition queries. multi-table joint queries are not unrelated to oracle.
II. modification
UPDATE tbl_name SET column to be changed
WHERE record to be updated
The WHERE clause is optional. Therefore, if not specified, each record in the table is updated. This is different from oracle.
For example, in the pet table, we find that the gender of the pet Whistler is not specified, so we can modify this record as follows:
Mysql> update pet set sex = 'F' where name = "Whistler ";
Delete
The DELETE statement has the following format:
Delete from tbl_name WHERE record to be deleted
The WHERE clause specifies which records should be deleted. It is optional, but if it is not selected, all records will be deleted. This means that the simplest DELETE statement is also the most dangerous.
This query clears all contents in the table. Be careful!
To delete a specific record, you can use the WHERE clause to select the record to be deleted. This is similar to the WHERE clause in the SELECT statement.
Mysql> delete from pet where name = "Whistler ";
You can use the following statement to clear the entire table:
Mysql> delete from pet;