Professional Documents
Culture Documents
Selecting Data Syntax
Selecting Data Syntax
Selecting data
Syntax
SELECT column1, column2, column3...
FROM table1, table2, table3...
WHERE condition1 AND condition2...
Creating tables
Syntax
CREATE TABLE database_name.table_name (
column1 <data type> PRIMARY KEY,
column2 <data type>,
column3 <data type>
);
Inserting Rows
Syntax
INSERT INTO table_name (column1, column2)
VALUES (value11, value12), (value21, value22), (value31, value32), ...
Updating Rows
Syntax
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE key = value
Deleting Rows
Syntax
DELETE FROM table_name WHERE column1 = value1 AND column2 =
value2 ...
Joining tables
Syntax
SELECT columns
FROM table1
INNER JOIN table2 ON table1.column = table2.column;
Group by
Syntax
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
Aggregate functions
COUNT counts how many rows are in a particular column.
SUM adds together all the values in a particular column.
MIN and MAX return the lowest and highest values in a particular column,
respectively.
AVG calculates the average of a group of selected values.
Having
Syntax
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
HAVING condition
Distinct
Syntax
SELECT DISTINCT column1, column2, ...
FROM table_name;
Order By
Syntax
SELECT column1, column2, ...
FROM table_name
ORDER BY column1, column2, ... ASC|DESC;