What is SQL? #
SQL stands for Structured Query Language. Query means the same as it does in normal English-to make a request or ask a question. So SQL is a programming language used to get information from a database.
It follows this kind of a structure:
DO SOMETHING from thisFile
Command | Description |
---|---|
SELECT * | selects all columns |
SELECT dog | selects the column dog |
FROM pets | from the column cats |
SELECT cats, dogs | gets both the dogs and cats column |
SELECT jumpMan AS Jumper from Fitness | renames the column jumpMan to Jumper |
SELECT DISTINCT year_hired FROM employees | selects unique year_hired so no repeating years appear |
CREATE VIEW view_name AS SELECT column1, column2, …FROM table_name | Saves SQL table so you can reuse it later on in the SQL file |
SQL Logic Operators #
Logic Operators lets you refine what you want to extract from a table.
Command | Description |
---|---|
ALL | True if all are true |
AND | True if A and B are true |
ANY | True if any statement is true |
BETWEEN | True if argument exists within range |
EXISTS | True if argument exists within rows |
IN | True if value is equal to a value in a list |
LIKE | True if argument matches a pattern |
NOT | Reverses the result of boolean operator |
OR | True if either argument is true |
SOME | True if some of the argument is true |