---
title: "Relational Data<br>SQL Queries"
author: "Keith VanderLinden<br>Calvin University"
output:
  xaringan::moon_reader:
    nature:
      titleSlideClass: ["left", "top"]
      highlightLines: true
      ratio: "16:9"     
---

```{r child = "../../resources/scripts/slide-setup.Rmd"}
```

```{r packages, echo = FALSE, warning = FALSE, message = FALSE}
knitr::opts_chunk$set(eval = TRUE)
options(dplyr.print_max = 12)
library(tidyverse)
```

# The Structured Query Language

.pull-left[
SQL is the standard language used to work with relational databases.
It provides a *data query language* (DQL).

<pre>   SELECT <i>list-of-field-names</i>
     FROM <i>list-of-table-names</i>
[    JOIN <i>join-table-condition</i>      ]
[   WHERE <i>list-of-filter-conditions</i> ]
[ORDER BY <i>list-of-order-fields</i>      ]</pre>

The clauses in square brackets (`[]`) are optional. 

`dplyr` functions were modeled on SQL.
]

???
- Queries retrieve data from databases.
- We now demo some basic SQL query commands, querying the same database using both:
  - `dplyr` commands in RStudio - Students can do this using the demo Rmd document.
  - SQL on ElephantSQL, a cloud database service - Only I can do this using my ElephantSQL login.

---
# Data Query Demo

.pull-left[
We now demo data queries using both `dplyr` and SQL. The demo will run queries on our local machine that access data from a cloud database system.

![cloud-sql deployment](images/rstudio-elephantsql-deployment.png)

We&rsquo;ll run RStudio on a local machine and connect to [ElephantSQL](https://www.elephantsql.com/).
]

???
The students may well be running RStudio in the cloud as well (rstudio.calvin.edu).
