SQL Cheat Sheet
Title | Syntax | Description |
---|---|---|
View SCHEMA for the Database | .SCHEMA | This will allow you to view the tables and commands for a SQL file. |
SQL SELECT Statement | SELECT * FROM table_name; *OR* SELECT column_name, column_name FROM table_name; |
The SELECT statement is used to select data from a database |
SQL SELECT DISTINCT Statement | SELECT DISTINCT column_name, column_name FROM table_name; |
The SELECT DISTINCT statement is used to return only distinct (different) values. In the event a table contains duplicate values, the keyword will return only distinct values. |
SQL WHERE Clause | SELECT column_name, column_name FROM table_name WHERE column_name operator value; |
The WHERE clause is used to filter records, extracting only those records that fulfill a specified criteria. |
SQL LIKE Operator | SELECT column_name FROM table_name WHERE column_name LIKE pattern; |
Searches for a specific pattern in the table records |
SQL IN Operator | SELECT column_name(s) FROM table_name WHERE column_name IN (value1, value2…); |
Allows you to specify multiple values in a WHERE clause |
SQL BETWEEN Operator | SELECT column_name(s) FROM table_name WHERE column_name BETWEEN value1 AND value2; |
Used to select values within a range. |
AND & OR Operators | SELECT column_name, column_name FROM table_name WHERE column_name operator value AND column_name operator value; |
Used to select values within a range. |
SQL ORDER BY Keyword | SELECT * FROM Customers ORDER BY column_name ASC, column_name DESC; | The ORDER BY keyword is used to sort the result-set by one or more columns. It will sort the records in ascending order by default. Use the DESC keyword to order them in descending order. |
SQL INSERT INTO Statement | INSERT INTO table_name VALUES (value1, value2, value3…); |
The INSERT INTO statement is used to insert new records in a table |
SQL UPDATE Statement | UPDATE table_name SET column = value1, column2 = value2,... WHERE same_column = some_value; |
UPDATE statement is used to update existing records on table. |
SQL DELETE Statement | DELETE FROM table_name WHERE same_column = some_value; |
The DELETE Statement deletes records in a table. |
SQL SELECT TOP Clause | DSELECT TOP number [or] percent PERCENT column_name(s) FROM table_name; |
Used to specify the number of records to return. |