You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 01-introduction.md
+17-16
Original file line number
Diff line number
Diff line change
@@ -53,7 +53,7 @@ into a field that should contain a number. Understanding the nature of relationa
53
53
databases, and using SQL, will help you in using databases in programming languages
54
54
such as R or Python.
55
55
56
-
Many web applications (including WordPress and ecommerce sites like Amazon) run on a SQL (relational) database. Understanding SQL is the first step in eventually building custom web applications that can serve data to users.
56
+
Many web applications (including WordPress and e-commerce sites like Amazon) run on a SQL (relational) database. Understanding SQL is the first step in eventually building custom web applications that can serve data to users.
57
57
58
58
## Why are people working in library- and information-related roles well suited to SQL?
59
59
@@ -77,7 +77,7 @@ direct way of finding information.
77
77
78
78
- You can use SQL to query your library database and explore new views that are not necessarily provided via library systems patron facing interfaces.
79
79
80
-
- SQL can be used to keep an inventory of items, for instance, for a library's makerspace, or it can be used to track licenses for journals.
80
+
- SQL can be used to keep an inventory of items, for instance, for a library's makerspace, or it can be used to track licences for journals.
81
81
82
82
- For projects involving migrating and cleaning data from one system to another, SQL can be a handy tool.
83
83
@@ -108,34 +108,35 @@ Let's all open the database we downloaded via the setup in DB Browser for SQLite
108
108
You can see the tables in the database by looking at the left hand side of the
109
109
screen under Tables.
110
110
111
-
To see the contents of a table, click on that table and then click on the Browse
112
-
Data tab above the table data.
111
+
To see the contents of a table, click on "Browse Data" then select the table in the "Table" dropdown in the upper left corner.
113
112
114
-
If we want to write a query, we click on the Execute SQL tab.
113
+
If we want to write a query, we click on the "Execute SQL" tab.
115
114
116
115
There are two ways to add new data to a table without writing SQL:
117
116
118
117
1. Enter data into a CSV file and append
119
118
2. Click the "Browse Data" tab, then click the "New Record" button.
120
119
121
-
The steps for adding data from a CSV file are:
120
+
To add data from a CSV file:
122
121
123
-
1. Choose "File" > "Import" > "Table" from CSV file...
124
-
2. DB Browser for SQLite will prompt you if you want to add the data to the existing table.
122
+
1. Choose "File" > "Import" > "Table from CSV file..."
123
+
2. Select a CSV file to import
124
+
3. Review the import settings and confirm that the column names and fields are correct
125
+
4. Click "OK" to import the data. If the table name matches an existing table and the number of columns match, DB Browser will ask if you want to add the data to the existing table.
125
126
126
127
## Dataset Description
127
128
128
-
The data we will be using consists of 5 csv files that contain tables of article titles, journals, languages, licenses, and publishers. The information in these tables are from a sample of 51 different journals published during 2015.
129
+
The data we will use was created from 5 csv files that contain tables of article titles, journals, languages, licences, and publishers. The information in these tables are from a sample of 51 different journals published during 2015.
129
130
130
131
**articles**
131
132
132
-
- Contains individual article Titles and the associated citations and metadata
133
+
- Contains individual article titles and the associated citations and metadata.
- Contains various journal Titles and associated metadata. The table also associates Journal Titles with ISSN numbers that are then referenced in the 'articles' table by the `ISSNs` field.
139
+
- Contains various journal titles and associated metadata. The table also associates Journal Titles with ISSN numbers that are then referenced in the 'articles' table by the `ISSNs` field.
139
140
- (5 fields, 51 records)
140
141
- Field names: `id`, `ISSN-L`,`ISSNs`, `PublisherID`, `Journal_Title`
141
142
@@ -145,9 +146,9 @@ The data we will be using consists of 5 csv files that contain tables of article
145
146
- (2 fields, 4 records)
146
147
- Field names: `id`, `Language`
147
148
148
-
**licenses**
149
+
**licences**
149
150
150
-
- ID table which associates License codes with id numbers. These id numbers are then referenced in the 'articles' table by the `LicenseID` field.
151
+
- ID table which associates Licence codes with id numbers. These id numbers are then referenced in the 'articles' table by the `LicenceID` field.
151
152
- (2 fields, 4 records)
152
153
- Field names: `id`, `Licence`
153
154
@@ -163,14 +164,14 @@ The main data types that are used in doaj-article-sample database are `INTEGER`
163
164
164
165
## SQL Data Type Quick Reference
165
166
166
-
Different database software/platforms have different names and sometimes different definitions of data types, so you'll need to understand the data types for any platform you are using. The following table explains some of the common data types and how they are represented in SQLite; [more details available on the SQLite website](https://www.sqlite.org/datatype3.html).
167
+
Different database software/platforms have different names and sometimes different definitions of data types, so you'll need to understand the data types for any platform you are using. The following table explains some of the common data types and how they are represented in SQLite; [more details available on the SQLite website](https://www.sqlite.org/datatype3.html).
| boolean or binary | this variable type is often used to represent variables that can only have two values: yes or no, true or false. | doesn't exist - need to use integer data type and values of 0 or 1. |
171
172
| integer | sometimes called whole numbers or counting numbers. Can be 1,2,3, etc., as well as 0 and negative whole numbers: -1,-2,-3, etc. | INTEGER |
172
173
| float, real, or double | a decimal number or a floating point value. The largest possible size of the number may be specified. | REAL |
173
-
| text or string |and combination of numbers, letters, symbols. Platforms may have different data types: one for variables with a set number of characters - e.g., a zip code or postal code, and one for variables with an open number of characters, e.g., an address or description variable. | TEXT |
174
+
| text or string |any combination of numbers, letters, symbols. Platforms may have different data types: one for variables with a set number of characters - e.g., a zip code or postal code, and one for variables with an open number of characters, e.g., an address or description variable. | TEXT |
174
175
| date or datetime | depending on the platform, may represent the date and time or the number of days since a specified date. This field often has a specified format, e.g., YYYY-MM-DD | doesn't exist - need to use built-in date and time functions and store dates in real, integer, or text formats. See [Section 2.2 of SQLite documentation](https://www.sqlite.org/datatype3.html#date_and_time_datatype) for more details. |
175
176
| blob | a Binary Large OBject can store a large amount of data, documents, audio or video files. | BLOB |
Copy file name to clipboardExpand all lines: 02-selecting-sorting-data.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -22,11 +22,11 @@ exercises: 5
22
22
23
23
## What is a query?
24
24
25
-
A query is a question or request for data. For example, "How many journals does our library subscribe to?" When we query a database, we can ask the same question using a common language called Structured Query Language or SQL in what is called a statement. Some of the most useful queries - the ones we are introducing in this first section - are used to return results from a table that match specific criteria.
25
+
A query is a question or request for data. For example, "How many journals does our library subscribe to?". When we query a database, we can ask the same question using Structured Query Language (SQL) in what is called a statement. Some of the most useful queries - the ones we are introducing in this first section - are used to return results from a table that match specific criteria.
26
26
27
27
## Writing my first query
28
28
29
-
Let's start by opening DB Browser for SQLite and the doaj-article-sample database (see Setup). Choose `Browse Data` and the `articles` table. The articles table contains columns or fields such as `Title`, `Authors`, `DOI`, `URL`, etc.
29
+
Let's start by opening DB Browser for SQLite and the doaj-article-sample database (see [Setup](/)). Click "Browse Data" and select the `articles` table in the "Table" dropdown menu. The articles table contains columns or fields such as `Title`, `Authors`, `DOI`, `URL`, etc.
30
30
31
31
Let's write a SQL query that selects only the `Title` column from the `articles` table.
32
32
@@ -60,7 +60,7 @@ SELECT Title, Authors, ISSNs, Year, DOI
60
60
FROM articles;
61
61
```
62
62
63
-
Or we can select all of the columns in a table using the wildcard `*`.
63
+
Or we can select all of the columns in a table using the wildcard `*`:
Copy file name to clipboardExpand all lines: 03-filtering.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ exercises: 10
20
20
21
21
## Filtering
22
22
23
-
SQL is a powerful tool for filtering data in databases based on a set of conditions. Let's say we only want data for a specific ISSN, for instance, for the *Acta Crystallographica* journal from the `articles` table. The journal has an ISSN code `2056-9890`. To filter by this ISSN code, we will use the `WHERE` clause.
23
+
SQL is a powerful tool for filtering data in databases based on a set of conditions. Let's say we only want data for a specific ISSN, for instance, for the *Acta Crystallographica* journal from the `articles` table. The journal has an ISSN code `2056-9890`. To filter by this ISSN code, we will use the `WHERE` clause.
24
24
25
25
```sql
26
26
SELECT*
@@ -44,7 +44,7 @@ ISSNs codes "2076-0787" and "2077-1444", we can combine the tests using OR:
44
44
```sql
45
45
SELECT*
46
46
FROM articles
47
-
WHERE (issns='2076-0787') OR (issns='2077-1444');
47
+
WHERE (ISSNs='2076-0787') OR (ISSNs='2077-1444');
48
48
```
49
49
50
50
When you do not know the entire value you are searching for, you can use comparison keywords such as `LIKE`, `IN`, `BETWEEN...AND`, `IS NULL`. For instance, we can use `LIKE` in combination with `WHERE` to search for data that matches a pattern.
Copy file name to clipboardExpand all lines: 04-ordering-commenting.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -68,7 +68,7 @@ WHERE (ISSNs IN ('2076-0787', '2077-1444', '2067-2764|2247-6202'));
68
68
```
69
69
70
70
We started with something simple, then added more clauses one by one, testing
71
-
their effects as we went along. For complex queries, this is a good strategy, to make sure you are getting what you want. Sometimes it might help to take a subset of the data that you can easily see in a temporary database to practice your queries on before working on a larger or more complicated database.
71
+
their effects as we went along. For complex queries, this is a good strategy, to make sure you are getting what you want. Sometimes it might help to take a subset of the data that you can easily see in a temporary database to practice your queries on before working on a larger or more complicated database.
72
72
73
73
When the queries become more complex, it can be useful to add comments to express to yourself, or to others, what you are doing with your query. Comments help explain the logic of a section and provide context for anyone reading the query. It's essentially a way of making notes within your SQL. In SQL, comments begin using <codeclass="language-plaintext highlighter-rouge">\--</code> and end at the end of the line. To mark a whole paragraph as a comment, you can enclose it with the characters /\* and \*/. For example, a commented version of the above query can be written as:
74
74
@@ -93,11 +93,11 @@ ON publishers.id = journals.PublisherId;
93
93
```
94
94
95
95
To see the introduction and explanation of JOINS, please click to [Episode 6](06-joins-aliases.md).
Copy file name to clipboardExpand all lines: 05-aggregating-calculating.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
title: Aggregating & calculating values
2
+
title: Aggregating and calculating values
3
3
teaching: 15
4
4
exercises: 5
5
5
---
@@ -72,7 +72,7 @@ For example, we can adapt the last request we wrote to only return information a
72
72
SELECT ISSNs, COUNT(*)
73
73
FROM articles
74
74
GROUP BY ISSNs
75
-
HAVINGcount(Title) >=10;
75
+
HAVINGCOUNT(Title) >=10;
76
76
```
77
77
78
78
The `HAVING` keyword works exactly like the `WHERE` keyword, but uses aggregate functions instead of database fields. When you want to filter based on an aggregation like `MAX, MIN, AVG, COUNT, SUM`, use `HAVING`; to filter based on the individual values in a database field, use `WHERE`.
@@ -108,7 +108,7 @@ In SQL, we can also perform calculations as we query the database. Also known as
In section [6\. Joins and aliases](06-joins-aliases.md) we are going to learn more about the SQL keyword `AS` and how to make use of aliases - in this example we simply used the calculation and `AS` to represent that the new column is different from the original SQL table data.
0 commit comments