SQL Flashcards
SQL
Structured Query Language
Standard language for relational database systems
Three SQL Statement Categories
DDL (Data Definition Language)
DML (Data Manipulation Language)
DCL (Data Control Language)
Commands that define a database, including creating, altering, and dropping tables and establishing constraints
-Create, Drop, Alter, Truncate
DDL (Data Definition Language)
DDL (Data Definition Language)
Commands that define a database, including creating, altering, and dropping tables and establishing constraints
-Create, Drop, Alter, Truncate
Commands that maintain and query a database
-Select, Insert, Update, Delete, Merge
DML (Data Manipulation Language)
DML (Data Manipulation Language)
Commands that maintain and query a database
-Select, Insert, Update, Delete, Merge
Commands that control a database, including administering privileges and committing data
-grant, revoke
DCL (Data Control Language)
DCL (Data Control Language)
Commands that control a database, including administering privileges and committing data
-grant, revoke
Requires order of included clauses
Select From Where Group By Having Order By
SELECT statement
Statement used for queries on a single table or for queries that involve multiple tables Clauses: Select From Where Group by/Having Order By
SQL Boolean Operators (used in where clause to join two conditions)
Not
And
Or
Order of the evaluation of operators
Not first
Then And
Then Or
SQL aggregate functions
Count Avg Max Min Sum
COUNT
The number of entries in a column that are not NULL
AVG
The average for entries in a column - argument must be numeric
MAX
The maximum value in a column (NULL values ignored)
MIN
The minimum value in a column (NULL values ignored)
SUM
The sum of the numeric values in a column
Used to summarize aggregations for records grouped by a given criteria. For each group, one record (row) is returned
GROUP BY
GROUP BY
Used to summarize aggregations for records grouped by a given criteria. For each group, one record (row) is returned
Used together with GROUP BY to specify “group-level” conditions to restrict the groups returned to only those satisfying the group condition(s)
HAVING
HAVING
Used together with GROUP BY to specify “group-level” conditions to restrict the groups returned to only those satisfying the group condition(s)
3 types of JOINs
INNER JOIN
LEFT (OUTER) JOIN
RIGHT (OUTER) JOIN
Returns only the set of records that match in both TABLE A and TABLE B (according to some attribute)
INNER JOIN
Returns only the set of records that match in both TABLE A and TABLE B (according to some attribute)
INNER JOIN
returns all the records in Table A and only the records that match from Table B. It leaves out records in B that have no match in A.
LEFT JOIN
LEFT JOIN
returns all the records in Table A and only the records that match from Table B. It leaves out records in B that have no match in A.
Returns all the records in Table B and only the records that match from Table A. It leaves out records in A that have no match in B
RIGHT JOIN
RIGHT JOIN
Returns all the records in Table B and only the records that match from Table A. It leaves out records in A that have no match in B