Home  >  Article  >  Complete collection of SQL query statements

Complete collection of SQL query statements

zbt
zbtOriginal
2023-11-17 11:19:184535browse

SQL query statements include SELECT statement, INSERT INTO statement, UPDATE statement, DELETE FROM statement, SELECT DISTINCT statement, WHERE clause, ORDER BY statement, GROUP BY statement, JOIN statement, IN statement, LIKE statement and BETWEEN statement.

Complete collection of SQL query statements

SQL(Structured Query Language) is a language used to manage relational database systems. It can be used to query, add, update and delete data in the database. The following are some commonly used SQL query statements:

1. SELECT statement: used to retrieve data from the database.

Example: SELECT * FROM table name;

2. INSERT INTO statement: used to insert new data into the database.

Example: INSERT INTO table name (column 1, column 2, column 3) VALUES (value 1, value 2, value 3);

3. UPDATE statement: used to update the database The data.

Example: UPDATE table name SET column 1 = value 1, column 2 = value 2 WHERE condition;

4. DELETE FROM statement: used to delete data from the database.

Example: DELETE FROM table name WHERE condition;

5. SELECT DISTINCT statement: used to retrieve unique data from the database.

Example: SELECT DISTINCT column name FROM table name;

6. WHERE clause: used to filter data that meets specified conditions.

Example: SELECT * FROM table name WHERE condition;

7. ORDER BY statement: used to sort the results according to the specified column.

Example: SELECT * FROM table name ORDER BY column name ASC/DESC;

8. GROUP BY statement: used to group results according to specified columns.

Example: SELECT column name 1, column name 2, COUNT(*) FROM table name GROUP BY column name 1, column name 2;

9. JOIN statement: used to combine multiple table for related queries.

Example: SELECT * FROM table name 1 JOIN table name 2 ON table name 1. column = table name 2. column;

10. IN statement: used to specify a collection, retrieve and Data that matches any value in the collection.

Example: SELECT * FROM table name WHERE column name IN (value 1, value 2, value 3);

11. LIKE statement: used for fuzzy matching in the WHERE clause.

Example: SELECT * FROM table name WHERE column name LIKE 'value%';

12. BETWEEN statement: used to specify a range and retrieve data within the range.

Example: SELECT * FROM table name WHERE column name BETWEEN value 1 AND value 2;

These are just a small part of the SQL query statements, SQL has many other functions and syntax. The specific use depends on the database you want to query and the specific needs. It is recommended to refer to relevant SQL tutorials and documentation for more detailed information and examples.

The above is the detailed content of Complete collection of SQL query statements. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn