Using JOINs
Joining data from two or more tables is how we unlock the power of a relational database such as MariaDB. There are three basic JOIN
types: INNER
, CROSS
, and LEFT
(or OUTER
).
Getting ready
Import the ISFDB database as described in the Importing the data exported by mysqldump recipe from Chapter 2, Diving Deep into MariaDB.
How to do it...
Launch the
mysql
command-line client application and connect to theisfdb
database on our MariaDB server.Perform an
INNER JOIN
of theauthors
andemails
tables to show us a list of authors and their corresponding e-mail addresses using the following command:SELECT author_canonical, email_address FROM authors INNER JOIN emails ON authors.author_id = emails.author_id;
Perform a
LEFT JOIN
of theemails
andauthors
tables to show us a list of authors and their corresponding e-mail addresses using the following command:SELECT author_canonical, email_address FROM emails LEFT JOIN authors ON authors.author_id = emails.author_id;
Perform...