SQL is one of the most powerful programming interfaces in the market. It enables you to ask a database for specific data in an interface optimized for efficient data access. However, writing SQL can be a cumbersome process, especially as it is not very similar to existing programming languages or business workflows such as Excel. This piece aims to explain the basics of SQL in a fun cheat sheet form that enables you to come away with a basis for writing your own SQL.
The below section helps to define the meaning of different terms in SQL and should help you find meaning in the phrases that, on first glance, may seem confusing!
SELECT: Retrieve data from one or more tables.some text
WHERE: Specify criteria to filter rows.some text
ORDER BY: Sort the result set.some text
CREATE TABLE: Create a new table.some text
INSERT INTO: Insert new data into a table.some text
UPDATE: Update existing data.some text
DELETE: Delete data.some text
ALTER TABLE: Modify an existing table structure.some text
DROP TABLE: Delete a table and its data.some text
PRIMARY KEY: Uniquely identifies each row in a table.
FOREIGN KEY: A key used to link two tables together.
NOT NULL: Ensures that a column cannot have a NULL value.
UNIQUE: Ensures all values in a column are different.
CHECK: Ensures that all values in a column satisfy a specific condition.
DEFAULT: Sets a default value for a column when no value is specified.
COUNT: Counts the number of rows.some text
SUM: Sums up the numeric values.some text
AVG: Calculates the average value.some text
MIN/MAX: Finds the minimum/maximum value.some text
INNER JOIN: Returns rows when there is at least one match in both tables.some text
LEFT JOIN (or LEFT OUTER JOIN): Returns all rows from the left table, and the matched rows from the right table.some text
RIGHT JOIN (or RIGHT OUTER JOIN): Returns all rows from the right table, and the matched rows from the left table.some text
FULL JOIN (or FULL OUTER JOIN): Returns rows when there is a match in one of the tables.some text
GROUP BY: Groups rows sharing a property so that an aggregate function can be applied to each group.some text
HAVING: Specify a filter condition for groups created by GROUP BY.some text
CASE: if-then-else logic in SQLsome text
LIKE: similarity testing in SQLsome text
COALESCE: alternative value if nullsome text
IN: Checks if a value matches any value in a list.some text
UNION: Combines results from multiple SELECT statements into a single result set, removing duplicates.some text
CAST: Converts a value from one data type to another.some text
DATE MANIPULATION: SQL DATABASE SPECIFIC
Below is a compact version of the above cheat sheet pieces. If you are new, intermediate, or even an expert in SQL, the below cheat sheet can be a helpful tool to have next to you as you write SQL.
SQL Cheat sheets can be incredibly helpful for getting started in writing SQL. Once we have written the basics for table creation, manipulating, and retrieval, the next step is to optimize that experience. This piece hopefully was a good overview on that first step of the SQL writing and optimization process. With these tools, hopefully you are able to write your own SQL and begin the process of data extraction in your own organization.