SQL notes

Home

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

mysql-logo.png

  • Check that the server is running with sudo systemctl status mysql.
  • Start the MySQL server with sudo systemctl start mysql and stop it with sudo 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, using root.

SQLite

Author: Alexander E. Zarebski

Created: 2025-05-05 Mon 13:21

Validate