[[SQL Concepts]]

List:

SELECT

Denotes what fields of data to show in the query Can select fields of data from other tables as well as the original ## FROM Denotes the table from which data will be pulled from Pretty simple. ## JOIN / ON JOIN: Denotes what tables should be ‘joined’ to the main table denoted by the FROM clause ON: Denotes what foreign keys will be used to connect tables Both used in conjunction to connect tables to each other

syntax: JOIN *new_table ON original_table.PK = new_table.FK

WHERE

Denotes how to filter data from table Works just like an IF statement without an ELSE Only filters raw data, it CANNOT filter aggregate data

GROUP BY

Specifies the field or fields that break the data into categories MUST HAVE minimum of one field to categorize MUST HAVE at least one expression with an aggregate value Often used a JOIN to provide categories ## HAVING Filters the categories from GROUP BY clause Runs after WHERE clause Runs after aggregate functions are calculated Filters by alias’s. NOT RAW DATA Filters by aggregates NOT RAW DATA Think of it as a post filter and the WHERE as a pre filter ## ORDER BY Denotes in what order to show result query Pretty simple. Choose what attribute to filter by ie. sort by name alphabetically, sort by highest to lowest. etc Uses ASC or DESC to define which way to summarize. ASC is default