SQL Flashcards
Returning first 10 rows in descinding order of Col_A from a table in SQLite filtered for when Col_A or Col_B are less than zero
SELECT * FROM Table_Name WHERE Col_A <0 OR Col_B <0 ORDER BY Col_A DESC LIMIT 10;
Returning a count of rows in a table
SELECT COUNT(Column_Name) FROM Table_Name;
Returning rows that match a list of values
SELECT *
FROM table
WHERE
column_name IN (‘value1’, ‘value2’, value3, ‘value4’);
Creating a view
CREATE VIEW View_name AS
SELECT * FROM Table_name;
Delete a view
DROP VIEW View_Name;
Append two select statements
[select_statement_one]
UNION
[select_statement_two];
Selecting rows that occur in both SELECT statements
[select_statement_one]
INTERSECT
[select_statement_two];
Selecting rows that occur in the first SELECT statement but not the second SELECT statement
[select_statement_one]
EXCEPT
[select_statement_two];
Launching the SQLite shell
sqlite3 chinook.db
Activate column headers in SQLite shell
.headers on
Activate column formatting for SQLite shell output
.mode column
Displaying help text in SQLite shell
.help
Display the list of tables and view of a database from SQLite shell
.tables
Run a BASH command from within SQLite shell
.shell [BASH_Command]
View a table’s schema from within SQLite shell
.schema [Table_Name]