Skip to content

Latest commit

 

History

History
81 lines (60 loc) · 1.71 KB

Chapter 2 - SELECT Statement.md

File metadata and controls

81 lines (60 loc) · 1.71 KB

Chapter 2 - The SELECT Statement

SELECT = 3-Resources/Tools/Developer Tools/Data Stack/Procedural Languages/SQL Code to retrieve data from database

Contents

Use Cases

  • View data from set of columns in a table
  • Combine data from multiple tables
  • Filter results from above, perform custom calculations, etc.

Syntax

SELECT [DISTINCT]
	[COLUMN],
	...
FROM
	[SCHEMA].[TABLENAME]
WHERE
	[CONDITIONAL STATEMENTS]
GROUP BY
	[GROUPING FIELDS]
HAVING
	[CONDITIONAL FILTER STATEMENTS AFTER GROUPING]
ORDER BY
	[COLUMNS TO SORT];

Select All:

SELECT * FROM [SCHEMA].[TABLENAME];

LIMIT

  • Sets maximum number of rows to return
  • Is always the last line of the query
SELECT *
FROM [SCHEMA].[TABLENAME]
LIMIT 5

ORDER BY

  • Sort output rows
  • Add ASC or DESC
    • In MySQL, NULL values appear first w/ ASC
SELECT * 
FROM [SCHEMA].[TABLENAME] 
ORDER BY [ORDERCOLUMN] DESC
LIMIT 5

Inline Calculations


Appendix: Links and References


Jimmy Briggs [email protected] | 2022