> data structure
→ data ~ tables ~ spreadsheets
- row = records
- columns = fields
- each col has a data type (integer, varchar (text), date, …)
> basic SQL commands
SELECTretrieve data from one or more tables → list the col to displayFROMwhich table, can be aliases? ?? ❓ASrename final column outputWITH table AS queryINSERTadd new records (rows) to a tableUPDATEmodify existing records (rows) in a tableDELETEremove records (rows) from a tableCREATE,ALTER,DROPmanage db objects like tables and schemas
> filtering and sorting
WHEREclause filters results based on certain conditionsORDER BYsorts data by specified columnsGROUP BYgroups rows sharing values in specified columns for agg functions (SUM, AVG, …)
> relationships and joins
JOIN ... ONINNER JOINLEFT JOINRIGHT JOINFULL JOINUSING
> advanced features
COUNTSUM,MAX,MIN,AVG
> logic, condition, …
OR,AND,NOT,BETWEEN,LIKEIS NULLvs.IS NOT NULLINvs.NOT IN
> others?
LIMITCASE
CASE
WHEN ... THEN ...
WHEN ... THEN ...
ELSE ...
END AS varname- concat texts
var1 || ' ' || var2 - convert
var::text - search substring
var::text LIKE '%SUBSTRING' - substr the first 6 char
LEFT(var, 6)