SQL notes
Table of Contents
Structured Query Language
Distinct
SELECT DISTINCT col FROM mytable;
Filtering and sorting
SELECT col_a, col_b FROM mytable WHERE condition ORDER BY col ASC/DESC LIMIT num_lim;
Joints
SELECT col_from_a, col_from_b FROM table_a INNER JOIN table_b ON table_a.id = table_b.matching_id WHERE condition ORDER BY col ASC/DESC LIMIT num_lim;
There are also LEFT
, RIGHT
and FULL
joins depending on which set
of rows you are sure you want in your results.
Database engines
MySQL
- Check that the server is running with
sudo systemctl status mysql
. - Start the MySQL server with
sudo systemctl start mysql
and stop it withsudo systemctl stop mysql
. - Log in with
sudo mysql -u <username> -p
. If you have just installed MySQL, then you'll need to set up a username and password, usingroot
.
SQLite
- DB Browser for SQLite is a GUI for inspecting and interactive with a SQLite database file.