Structured Query Language
ManipulationCreate TableCREATE TABLE table_name (column1_name data_type, column2_name data_type, etc.);
This creates a new table in your database. You can include as many columns as you want. Alter TableALTER TABLE table ADD COLUMN new_column data_type;
Modify the columns in a table. SelectSELECT column1, column2, etc. FROM table;
This pulls data from a table. Select DistinctSELECT DISTINCT column FROM table;
Select every unique value in a column. InsertINSERT INTO table (column1, column2, etc.) VALUES (value1, value2, etc.);
This inserts a row into the specified table. UpdateUPDATE table SET column1 = new_value WHERE column2 = value;
This updates data in a table. You can change the data in a column for all rows meeting certain criteria. Delete FromDELETE FROM table WHERE column IS criteria;
Delete rows in a table. |
QueriesLikeSELECT column FROM table WHERE column LIKE criteria;
Return rows where data in the specified column matches the criteria. AndSELECT column FROM table WHERE column1 = criteria1 AND column 2 = criteria2;
Link multiple search criteria in a single query. Between ... And ...SELECT column FROM table WHERE column BETWEEN criteria1 AND criteria2;
Search for rows with values between two boundary values. OrSELECT column FROM table WHERE column1 = criteria1 OR column2 = criteria2;
Search for rows that satisfy at least one of a given OR statement. Order bySELECT column FROM table ORDER BY criteria ASC;
Return the columns, ordered either ascending (smallest to largest, ASC) or descending (largest to smallest, DESC). LimitSELECT column FROM table LIMIT number;
Return up to the limit rows meeting your search criteria. |
Aggregate FunctionsCountSELECT COUNT(column) FROM table;
Return a count of rows with column =/= NULL. To see all rows, set column = * Group BySELECT column1, FUNCTION(column2) FROM table GROUP BY column1;
Groups the results by the distinct values in column1. Works best with aggregator functions. SumSELECT SUM(column) FROM table;
Aggregates sum for the specified column. MaxSELECT MAX(column) FROM table;
Finds the maximum value within the specified column. MinSELECT MIN(column) FROM table;
Finds the minimum value within the specified column. AverageSELECT AVG(column) FROM table;
Finds the average value of a specified column. RoundSELECT ROUND(column, decimal_places) FROM table;
Rounds the given output to the stated number of decimal places. If decimal_places is excluded, it will round to the nearest integer. |
Multiple TablesPrimary KeyCREATE TABLE table_name (id INTEGER PRIMARY KEY, column2_name data_type2, etc.);
The primary key acts as the id value for the record. Each value in this column will be unique, and no value will be NULL. Inner JoinSELECT table1.column, table2.column
The inner join returns only the records from table1 that join to table2. Left Outer JoinSELECT table1.column, table2.column
The outer join returns all records from table1. If they join to table2, it will show the joined data. If they don't join, it will return NULL in the joined columns. AliasSELECT
Use AS to create a new alias for each column in the query results. |