Solution to Activity 13.1
In this activity, you will find the list of the heads of state of all monarchies. The data will be fetched in the CSV format so that you can load it in Excel and later incorporate it into an article. Follow these steps to complete this activity:
- Open the MySQL client and connect to the
world
database:USE world
This query produces the following output:
- Select the columns we need and filter out the monarchies:
SELECT Name, HeadOfState FROM country WHERE GovernmentForm LIKE '%Monarchy%';
- Send the result to a file named
monarchy.csv
:SELECT Name, HeadOfState FROM country WHERE GovernmentForm LIKE '%Monarchy%' INTO OUTFILE '/var/lib/mysql-files/monarchy.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"';
This query produces the following output: