Basic query:
Select column name from table name "Base Query" (SQL is case insensitive)
DISTINCT: Go to duplicate value
SELECT DISTINCT column name from table name (de-duplicated value)
WHERE: Select Standard
SELECT column name from table name WHERE column operator value
(SQL uses single quotation marks to wrap text values (most database systems also accept double quotes). If it is a numeric value, do not use quotation marks. )
and And OR: and/or
SELECT column name from table name WHERE * and/or*
SELECT * from Persons WHERE firstname= ' Thomas ' and lastname= ' Carter '
lect * from Persons WHERE firstname= ' Thomas ' OR lastname= ' Carter '
SELECT * from Persons WHERE (firstname= ' Thomas ' OR firstname= ' William ') and lastname= ' Carter ' use parentheses to form complex expressions
ORDER BY statement: Sort
SELECT Company, OrderNumber from Orders ORDER by Company (DESC)/ordernumber
Insert into statement: Inserting Rows/Columns
INSERT into table name values (value 1, value 2,....)
INSERT into table_name (column 1, column 2,...) Values (value 1, value 2,....)
UPDATE statement: Modifying data/Updates in a table
UPDATE table name SET column name = new value WHERE Column name = value
Delete statement: Delete rows from a table
DELETE from table name WHERE column name = value--------------------------------------------------------------Toplike (The specified pattern in the search column in the WHERE clause) in (specifying multiple values in the WHERE clause) Between (Between ... and selects a range of data between two values alias (you can specify an alias for the column name and table name) (Lnner/left/right/full) joinunion (the result set of merging two or more SELECT statements) SELECT INTO ( The statement can be used to create a backup copy of the table. Create database (for creating databases) CREATE TABLE (statement to create a table in the database) Constraints-constraint-----------------------not NULL constraint ( Constraints enforce columns do not accept NULL values)-----------------------UNIQUE constraint (a constraint uniquely identifies each record in a database table)-----------------------PRIMARY KEY constraint ( Constraints uniquely identify each record in a database table-----------------------FOREIGN KEY constraint-----------------------CHECK Constraint-----------------------DEFAULT constraint CREATE INDEX (statement used to create an index in a table) SQL revoke index, table, and database---------------------------DROP index command to delete an index in a table--------------------the DROP TABLE statement is used to delete tables (the structure, properties, and indexes of the table are also deleted)--------------------drop DATABASE Statement to delete a database--------------------TRUNCATE table simply deletes data from the table the ALTER TABLE statement is used to add to an existing table, Modify or delete a column-------------------------------function---------------------------------------------------
avg function returns the average of a numeric columnSELECT AVG (column_name) from table_name
the Count () function returns the number of rows that match the specified criteriaSELECT COUNT (column_name) from table_name
The first () function returns the value of record one in the specified fieldSELECT First (column_name) from table_name
The last () function returns the value of the final record in the specified field. SELECT last (column_name) from table_name
the Max function returns the maximum value in a columnSELECT MAX (column_name) from table_name
the Min function returns the minimum value in a columnSELECT MIN (column_name) from table_name
The SUM function returns the total number of numeric columnsSELECT SUM (column_name) from table_name
the GROUP BY statement is used to combine aggregate functions to group result sets based on one or more columns
HAVING clause: increasing the HAVING clause in SQL because the WHERE keyword cannot be used with an aggregate function
The UCASE function converts the value of a field to uppercaseSELECT UCASE (column_name) from table_name
The LCASE function converts the value of a field to lowercaseSELECT LCASE (column_name) from table_name
The MID function is used to extract characters from a text fieldSELECT MID (Column_name,start[,length]) from table_name
The LEN function returns the length of a value in a text fieldSELECT LEN (column_name) from table_name
The ROUND function is used to round a numeric field to a specified number of decimal digitsSELECT ROUND (column_name,decimals) from table_name
the NOW function returns the current date and timeSELECT now () from table_name
The format function is used for formatting the display of a fieldElect FORMAT (Column_name,format) from table_name
SQL syntax with