Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions concepts/select/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"blurb": "The SQL SELECT statement is the mechanism for querying a database.",
"authors": ["blackk-foxx"],
"contributors": ["blackk-foxx"]
}
142 changes: 142 additions & 0 deletions concepts/select/about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# The SELECT statement

In SQL, a `SELECT` statement allows you to retrieve data from a database.
The result of a `SELECT` statement is a result set -- some number of values arranged in rows and columns, where each column is a particular attribute of the data and each row is a set of values for each column.

Roughly, you can think of the set of columns as a data structure, where each column represents a field of the data structure, and each row represents a concrete instance of the data structure.

With a `SELECT` statement, you can specify the data you want and optionally transform, filter, and/or modify the shape of the output data.


## The basics

The anatomy of a basic `SELECT` statement is as follows:

```sql
SELECT <columns>
FROM <source>
WHERE <criteria>;
```

Note that the line breaks are not required; any spacing will suffice to separate the different
clauses (i.e. parts) of the `SELECT` statement.

Immediately following the `SELECT` keyword is a list of the columns that you want in the result.
The `FROM` clause identifies the source of the data, which is typically a table in the database.
The `WHERE` clause filters the output data by one or more criteria.


For example, consider a database with a table named `inventory` containing the following data:
Comment on lines +33 to +35
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The `WHERE` clause filters the output data by one or more criteria.
For example, consider a database with a table named `inventory` containing the following data:
The `WHERE` clause filters the output data by one or more criteria.
For example, consider a database with a table named `inventory` containing the following data.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied here and elsewhere.



| upc | category | supplier | brand | product_name | weight | stock |
|--------------|------------|----------------|-------------|----------------------------------|--------|-------|
| 812345670019 | Cookware | KitchenCo | HearthStone | 10" Non-Stick Skillet | 1.8 | 42 |
| 845678120334 | Utensils | HomePro Supply | PrepMaster | Stainless Steel Ladle | 0.4 | 120 |
| 899001234556 | Appliances | Culinary Depot | QuickBrew | Single-Serve Coffee Maker | 4.2 | 18 |
| 823450987112 | Cookware | KitchenCo | FreshKeep | 12-Piece Glass Container Set | 6 | 33 |
| 867530900221 | Utensils | HomePro Supply | EdgeCraft | 8' Chef's Knife | 0.6 | 27 |
| 880012349876 | Appliances | Culinary Depot | HeatWave | Compact Toaster Oven | 7.5 | 14 |
| 833221109443 | Utensils | HomePro Supply | PureScrub | Heavy-Duty Kitchen Sponge (3-pk) | 0.2 | 200 |
| 899998877665 | Cookware | KitchenCo | IronCraft | Cast-Iron Grill Pan | 5.3 | 21 |
| 844110220987 | Appliances | Culinary Depot | BlendPro | High-Speed Personal Blender | 3.1 | 16 |

If we want to simply retrieve all of the data from the table, we could run the following query:

```sql
SELECT * FROM inventory;
```

Result:

```
upc category supplier brand product_name weight stock
------------ ---------- -------------- ----------- -------------------------------- ------ -----
812345670019 Cookware KitchenCo HearthStone 10" Non-Stick Skillet 1.8 42
845678120334 Utensils HomePro Supply PrepMaster Stainless Steel Ladle 0.4 120
899001234556 Appliances Culinary Depot QuickBrew Single-Serve Coffee Maker 4.2 18
823450987112 Cookware KitchenCo FreshKeep 12-Piece Glass Container Set 6 33
867530900221 Utensils HomePro Supply EdgeCraft 8' Chef's Knife 0.6 27
880012349876 Appliances Culinary Depot HeatWave Compact Toaster Oven 7.5 14
833221109443 Utensils HomePro Supply PureScrub Heavy-Duty Kitchen Sponge (3-pk) 0.2 200
899998877665 Cookware KitchenCo IronCraft Cast-Iron Grill Pan 5.3 21
844110220987 Appliances Culinary Depot BlendPro High-Speed Personal Blender 3.1 16
```

But if we only want the category and product_name values, we could specify those columns:

```sql
SELECT category, product_name FROM inventory;
```

Result:

```
category product_name
---------- --------------------------------
Cookware 10" Non-Stick Skillet
Utensils Stainless Steel Ladle
Appliances Single-Serve Coffee Maker
Cookware 12-Piece Glass Container Set
Utensils 8' Chef's Knife
Appliances Compact Toaster Oven
Utensils Heavy-Duty Kitchen Sponge (3-pk)
Cookware Cast-Iron Grill Pan
Appliances High-Speed Personal Blender
```

~~~~exercism/note
The `FROM` clause is optional.
A statement like `SELECT "Hello, world.";` is perfectly valid, and will generate the following result:

```
"Hello, world."
---------------
Hello, world.
```
~~~~

## Filtering data with the WHERE clause

The `WHERE` clause allows you to filter the data retrieved by a `SELECT` statement.
For example, if we only want Appliances:

```sql
SELECT * FROM inventory
WHERE category = "Appliances";
```

Result:
```
upc category supplier brand product_name weight stock
------------ ---------- -------------- --------- --------------------------- ------ -----
899001234556 Appliances Culinary Depot QuickBrew Single-Serve Coffee Maker 4.2 18
880012349876 Appliances Culinary Depot HeatWave Compact Toaster Oven 7.5 14
844110220987 Appliances Culinary Depot BlendPro High-Speed Personal Blender 3.1 16
```


Or maybe we only want data where the weight is between 2.0 and 6.0:

```sql
SELECT * FROM inventory
WHERE weight BETWEEN 2.0 AND 6.0;
```


Result:
```
upc category supplier brand product_name weight stock
------------ ---------- -------------- --------- ---------------------------- ------ -----
899001234556 Appliances Culinary Depot QuickBrew Single-Serve Coffee Maker 4.2 18
823450987112 Cookware KitchenCo FreshKeep 12-Piece Glass Container Set 6 33
899998877665 Cookware KitchenCo IronCraft Cast-Iron Grill Pan 5.3 21
844110220987 Appliances Culinary Depot BlendPro High-Speed Personal Blender 3.1 16
```


In addition to `=` and `BETWEEN...AND`, the `WHERE` clause supports a wide range of expressions, including comparison (`<`, `<=`, `>`, `>=`), pattern matching (`LIKE`, `GLOB`, `REGEXP`, `MATCH`), and checking for membership in a list (`IN`, `NOT IN`).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of the pattern matching operators are probably specific to sqlite. Did you want to stay more db-neutral?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really have a strong opinion here. I guess it would be nice to stay as generic as possible, but the concept docs do provide links to SQLite specific docs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the SQLite track, not a generic SQL track. I think SQLite specific things are completely fine, and probably even preferred.

See [SQL Language Expressions](sql-expr) for the complete documentation.


[sql-expr]: https://sqlite.org/lang_expr.html
142 changes: 142 additions & 0 deletions concepts/select/introduction.md
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the same as the about.md?

Copy link
Copy Markdown
Author

@blackk-foxx blackk-foxx Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, except for the initial heading.

Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# The SELECT statement

In SQL, a `SELECT` statement allows you to retrieve data from a database.
The result of a `SELECT` statement is a result set -- some number of values arranged in rows and columns, where each column is a particular attribute of the data and each row is a set of values for each column.

Roughly, you can think of the set of columns as a data structure, where each column represents a field of the data structure, and each row represents a concrete instance of the data structure.

With a `SELECT` statement, you can specify the data you want and optionally transform, filter, and/or modify the shape of the output data.


## The basics

The anatomy of a basic `SELECT` statement is as follows:

```sql
SELECT <columns>
FROM <source>
WHERE <criteria>;
```

Note that the line breaks are not required; any spacing will suffice to separate the different
clauses (i.e. parts) of the `SELECT` statement.

Immediately following the `SELECT` keyword is a list of the columns that you want in the result.
The `FROM` clause identifies the source of the data, which is typically a table in the database.
The `WHERE` clause filters the output data by one or more criteria.


For example, consider a database with a table named `inventory` containing the following data:


| upc | category | supplier | brand | product_name | weight | stock |
|--------------|------------|----------------|-------------|----------------------------------|--------|-------|
| 812345670019 | Cookware | KitchenCo | HearthStone | 10" Non-Stick Skillet | 1.8 | 42 |
| 845678120334 | Utensils | HomePro Supply | PrepMaster | Stainless Steel Ladle | 0.4 | 120 |
| 899001234556 | Appliances | Culinary Depot | QuickBrew | Single-Serve Coffee Maker | 4.2 | 18 |
| 823450987112 | Cookware | KitchenCo | FreshKeep | 12-Piece Glass Container Set | 6 | 33 |
| 867530900221 | Utensils | HomePro Supply | EdgeCraft | 8' Chef's Knife | 0.6 | 27 |
| 880012349876 | Appliances | Culinary Depot | HeatWave | Compact Toaster Oven | 7.5 | 14 |
| 833221109443 | Utensils | HomePro Supply | PureScrub | Heavy-Duty Kitchen Sponge (3-pk) | 0.2 | 200 |
| 899998877665 | Cookware | KitchenCo | IronCraft | Cast-Iron Grill Pan | 5.3 | 21 |
| 844110220987 | Appliances | Culinary Depot | BlendPro | High-Speed Personal Blender | 3.1 | 16 |

If we want to simply retrieve all of the data from the table, we could run the following query:

```sql
SELECT * FROM inventory;
```

Result:

```
upc category supplier brand product_name weight stock
------------ ---------- -------------- ----------- -------------------------------- ------ -----
812345670019 Cookware KitchenCo HearthStone 10" Non-Stick Skillet 1.8 42
845678120334 Utensils HomePro Supply PrepMaster Stainless Steel Ladle 0.4 120
899001234556 Appliances Culinary Depot QuickBrew Single-Serve Coffee Maker 4.2 18
823450987112 Cookware KitchenCo FreshKeep 12-Piece Glass Container Set 6 33
867530900221 Utensils HomePro Supply EdgeCraft 8' Chef's Knife 0.6 27
880012349876 Appliances Culinary Depot HeatWave Compact Toaster Oven 7.5 14
833221109443 Utensils HomePro Supply PureScrub Heavy-Duty Kitchen Sponge (3-pk) 0.2 200
899998877665 Cookware KitchenCo IronCraft Cast-Iron Grill Pan 5.3 21
844110220987 Appliances Culinary Depot BlendPro High-Speed Personal Blender 3.1 16
```

But if we only want the category and product_name values, we could specify those columns:

```sql
SELECT category, product_name FROM inventory;
```

Result:

```
category product_name
---------- --------------------------------
Cookware 10" Non-Stick Skillet
Utensils Stainless Steel Ladle
Appliances Single-Serve Coffee Maker
Cookware 12-Piece Glass Container Set
Utensils 8' Chef's Knife
Appliances Compact Toaster Oven
Utensils Heavy-Duty Kitchen Sponge (3-pk)
Cookware Cast-Iron Grill Pan
Appliances High-Speed Personal Blender
```

~~~~exercism/note
The `FROM` clause is optional.
A statement like `SELECT "Hello, world.";` is perfectly valid, and will generate the following result:

```
"Hello, world."
---------------
Hello, world.
```
~~~~

## Filtering data with the WHERE clause

The `WHERE` clause allows you to filter the data retrieved by a `SELECT` statement.
For example, if we only want Appliances:

```sql
SELECT * FROM inventory
WHERE category = "Appliances";
```

Result:
```
upc category supplier brand product_name weight stock
------------ ---------- -------------- --------- --------------------------- ------ -----
899001234556 Appliances Culinary Depot QuickBrew Single-Serve Coffee Maker 4.2 18
880012349876 Appliances Culinary Depot HeatWave Compact Toaster Oven 7.5 14
844110220987 Appliances Culinary Depot BlendPro High-Speed Personal Blender 3.1 16
```


Or maybe we only want data where the weight is between 2.0 and 6.0:

```sql
SELECT * FROM inventory
WHERE weight BETWEEN 2.0 AND 6.0;
```


Result:
```
upc category supplier brand product_name weight stock
------------ ---------- -------------- --------- ---------------------------- ------ -----
899001234556 Appliances Culinary Depot QuickBrew Single-Serve Coffee Maker 4.2 18
823450987112 Cookware KitchenCo FreshKeep 12-Piece Glass Container Set 6 33
899998877665 Cookware KitchenCo IronCraft Cast-Iron Grill Pan 5.3 21
844110220987 Appliances Culinary Depot BlendPro High-Speed Personal Blender 3.1 16
```


In addition to `=` and `BETWEEN...AND`, the `WHERE` clause supports a wide range of expressions, including comparison (`<`, `<=`, `>`, `>=`), pattern matching (`LIKE`, `GLOB`, `REGEXP`, `MATCH`), and checking for membership in a list (`IN`, `NOT IN`).
See [SQL Language Expressions](sql-expr) for the complete documentation.


[sql-expr]: https://sqlite.org/lang_expr.html
10 changes: 10 additions & 0 deletions concepts/select/links.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"url": "https://sqlite.org/lang_select.html#simple_select_processing",
"description": "Simple SELECT processing details"
},
{
"url": "https://sqlite.org/lang_select.html",
"description": "Complete SELECT documentation for SQLite"
}
]
18 changes: 18 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@
]
},
"exercises": {
"concept": [
{
"slug": "intro-select",
"name": "SELECT Basics",
"uuid": "1762549a-4622-442d-9aff-4c65f72a955c",
"concepts": [
"select"
],
"prerequisites": []
}
],
"practice": [
{
"slug": "hello-world",
Expand Down Expand Up @@ -716,6 +727,13 @@
"icon": "small"
}
],
"concepts": [
{
"uuid": "92187df0-fb68-4b46-af3b-cc17c2ef6fbc",
"slug": "select",
"name": "SELECT"
}
],
"tags": [
"execution_mode/interpreted",
"platform/linux",
Expand Down
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are hints needed for this one? I'm open to suggestions...

Empty file.
28 changes: 28 additions & 0 deletions exercises/concept/intro-select/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Instructions

You are a data analyst at a firm that analyzes weather data in the Pacific Northwest. You will be working with a database containing a `weather_readings` table with the following columns:

* `date`: The date on which the sample was collected.
* `location`: The name of the city in which the sample was collected.
* `temperature`: The temperature, in degrees Fahrenheit.
* `humidity`: The relative humidity, as a percentage value.

In each of the following tasks, your job is to gather the specified result set, by using a `SELECT` statement.
Note that in each case, the result set will be stored in a new table -- one table for each task -- via a pre-written `CREATE TABLE` statement.
Your job for each task is to add the appropriate `SELECT` statement within the existing `CREATE TABLE` statement.

## 1. Gather all of the data
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "gather" a technical term? The concept doc doesn't mention "gather" IIRC.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now using the same "retrieve" verb as in the doc.


Gather all of the data from the `weather_readings` table.

## 2. Gather only the location and temperature data

Gather only the location and temperature values from the `weather_readings` table.

## 3. Gather only data for Seattle

Gather only the data for the Seattle location.

## 4. Gather only the data with humidity in a specific range

Gather only the data where the humidity is between 60% and 70%.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would that be BETWEEN 60 AND 70 or BETWEEN 0.60 AND 0.70?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. Given the current data format, it would be integers. But maybe the humidity should be decimal values instead?

Loading