datalitico.com

SQL Commands
CommandSyntaxExplanation
SELECTSELECT column1, column2, ... FROM table_name;Retrieves data from one or more database tables.
FROMSELECT * FROM table_name;Specifies the source table from which data is retrieved.
WHERESELECT * FROM table_name WHERE condition;Filters data based on a specified condition.
DISTINCTSELECT DISTINCT column1, column2, ... FROM table_name;Retrieves unique values from specified columns.
ORDER BY`SELECT column1, column2, ... FROM table_name ORDER BY column1 ASCDESC, column2 ASC
GROUP BYSELECT column1, column2, ... FROM table_name GROUP BY column1, column2, ...;Groups rows with identical values in specified column(s).
HAVINGSELECT column1, column2, ... FROM table_name GROUP BY column1, column2, ... HAVING condition;Filters grouped data based on a condition.
INSERT INTOINSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);Inserts new rows into a table.
UPDATEUPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;Modifies existing records in a table.
DELETE FROMDELETE FROM table_name WHERE condition;Deletes rows from a table based on a condition.
COUNTSELECT COUNT(column) FROM table_name;Counts the number of rows in a result set or the number of occurrences of a specific value in a column.
SUMSELECT SUM(column) FROM table_name;Calculates the sum of values in a numeric column.
AVGSELECT AVG(column) FROM table_name;Calculates the average of values in a numeric column.
MINSELECT MIN(column) FROM table_name;Retrieves the minimum value from a column.
MAXSELECT MAX(column) FROM table_name;Retrieves the maximum value from a column.
BETWEENSELECT column1, column2, ... FROM table_name WHERE column BETWEEN value1 AND value2;Filters data within a specified range.
LIKESELECT column1, column2, ... FROM table_name WHERE column LIKE pattern;Filters data based on a specified pattern.
INSELECT column1, column2, ... FROM table_name WHERE column IN (value1, value2, ...);Filters data based on a list of values.
IS NULLSELECT column1, column2, ... FROM table_name WHERE column IS NULL;Filters data where a column is null.
IS NOT NULLSELECT column1, column2, ... FROM table_name WHERE column IS NOT NULL;Filters data where a column is not null.
JOINSELECT * FROM table1 JOIN table2 ON table1.column = table2.column;Combines rows from two or more tables based on a related column.
LEFT JOINSELECT * FROM table1 LEFT JOIN table2 ON table1.column = table2.column;Retrieves all rows from the left table and matching rows from the right table.
RIGHT JOINSELECT * FROM table1 RIGHT JOIN table2 ON table1.column = table2.column;Retrieves all rows from the right table and matching rows from the left table.
FULL OUTER JOINSELECT * FROM table1 FULL OUTER JOIN table2 ON table1.column = table2.column;Retrieves all rows when there is a match in either the left or right table.
UNIONSELECT column1, column2, ... FROM table1 UNION SELECT column1, column2, ... FROM table2;Combines the result sets of two or more SELECT statements into a single result set.
UNION ALLSELECT column1, column2, ... FROM table1 UNION ALL SELECT column1, column2, ... FROM table2;Combines the result sets of two or more SELECT statements into a single result set, including duplicates.
CREATE DATABASECREATE DATABASE database_name;Creates a new database.
DROP DATABASEDROP DATABASE database_name;Deletes an existing database.
CREATE TABLECREATE TABLE table_name (column1 datatype, column2 datatype, ...);Creates a new table with specified columns and data types.
ALTER TABLEALTER TABLE table_name ADD column_name datatype;Adds a new column to an existing table.
DROP TABLEDROP TABLE table_name;Deletes an existing table.
CREATE INDEXCREATE INDEX index_name ON table_name (column1, column2, ...);Creates an index on specified columns to improve query performance.
DROP INDEXDROP INDEX index_name;Deletes an existing index.
CREATE VIEWCREATE VIEW view_name AS SELECT column1, column2, ... FROM table_name WHERE condition;Creates a virtual table based on the result of a SELECT query.
DROP VIEWDROP VIEW view_name;Deletes an existing view.
GRANTGRANT permissions ON object TO user;Grants specific permissions on an object (table, view) to a user.
REVOKEREVOKE permissions ON object FROM user;Revokes specific permissions on an object from a user.
COMMITCOMMIT;Saves changes made during the current transaction.
ROLLBACKROLLBACK;Undoes changes made during the current transaction.
Scroll to Top