Lists of SQL command
These are a list of fundamental SQL command to use.
If you liked to learn more, go to the cheatsheet that is named the same as the command name.
Retrieving data
| Query | Usage | Requirements | Optional Modifier |
|---|---|---|---|
| SELECT Choosing a column | SELECT [column_name] ... | FROM | ... DISTINCT [column_name]... AS [new_column_name][group_function] |
| FROM Choosing a table source | ... FROM [table_name] | SELECT | |
| WHERE Choosing with arguments | ... WHERE [arguments] | SELECT & FROM | |
| ORDER BY Reordering result with arguments | ... ORDER BY [column_name] [ASC / DESC] | SELECT & FROM |
Manipulating table (object)
| Query | Usage |
| -------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | --- |
| CREATE TABLE
Create a new table from scratch | CREATE TABLE [table_name] ( [constraint] [column_name] [data_type] ); |
| ALTER TABLE
Edit table column attributes | ALTER TABLE [table_Name] +
ADD [column_name] [data_type]; or
ALTER COLUMN [column_name] [data_type]; or
DROP [column_name] [data_type]; |
| DROP TABLE
Delete the table from existence
similar : DELETE | DROP TABLE [table_name]; | |
Data grouping
| Query | Usage | Requirements | Optional Modifier |
|---|---|---|---|
| GROUP BY Choose the group that will do the group function | GROUP BY [column_name] | SELECT & FROM & Column functions | HAVING |
| HAVING Allows GROUP to have some arguments | HAVING [arguments] | GROUP |
Manipulating data
| Query | Usage | Requirements |
|---|---|---|
| INSERT INTO Add new column to table | INSERT INTO [table_name] | VALUES [column_values] |
| UPDATE Edit column attributes | UPDATE [table_name] | SET [column_name] = [argument] WHERE[argument] |
| DELETE FROM Delete column from the table | DELETE FROM [table_name] | WHERE [arguments] |
Merging data table
| Query | Usage | Requirements |
|---|---|---|
| INNER JOIN Result will be matched only | INNER JOIN [table_name] or JOIN [table_name] | ... ON [currentTable_column_name] = [targetTable_column_name] or... USING [key_column_Name] |
| OUTER JOIN Result will be matched + some table | LEFT JOIN [table_name] orRIGHT JOIN [table_name] orFULL JOIN [table_name] | ... ON [currentTable_column_name] = [targetTable_column_name] or... USING [key_column_Name] |
| NATURAL JOIN Automatic finding of merging key similar : EQUI JOIN | NATURAL JOIN [table_name] | ... ON [currentTable_column_name] = [targetTable_column_name] or... USING [key_column_Name] |
Additional table controls
| Query | Usage |
|---|---|
| RENAME Rename a table name | RENAME [table_name] [new_table_name] |
| SET INTEGRITY Set Foreign Key Integrity Rule | SET FOREIGN_KEY_CHECKS = [true / false] |
Transaction control
| Query | Usage |
|---|---|
| COMMIT Commit all transactions created from last checkpoint | COMMIT |
| ROLLBACK Revert all transactions to last checkpoint | ROLLBACK [checkpoint_name] |
| SAVEPOINT Create a new checkpoint | SAVEPOINT [new_savepoint_name] |