From 866f7af4b51cf7878f7dd9d5eea517afbd10edbe Mon Sep 17 00:00:00 2001 From: Todd Schwartz Date: Sat, 25 Oct 2025 15:46:24 -0700 Subject: [PATCH 1/5] Add basic SELECT concept --- concepts/select/about.md | 159 ++++++++++++++++++++++++++++++++ concepts/select/introduction.md | 4 + concepts/select/links.json | 10 ++ 3 files changed, 173 insertions(+) create mode 100644 concepts/select/about.md create mode 100644 concepts/select/introduction.md create mode 100644 concepts/select/links.json diff --git a/concepts/select/about.md b/concepts/select/about.md new file mode 100644 index 00000000..d4d92d34 --- /dev/null +++ b/concepts/select/about.md @@ -0,0 +1,159 @@ +# The SELECT statement + +When you want to retrieve data from a database, you issue a query. In SQL, you issue a query using the `SELECT` statement. The result of a `SELECT` statement is a dataset -- 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 +FROM +WHERE ; +``` + +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 `weather_readings` containing the following data: + + +| date | place | temperature | humidity | +|------------|--------------|-------------|----------| +| 2025-10-22 | Portland | 53.1 | 72 | +| 2025-10-22 | Seattle | 56.2 | 66 | +| 2025-10-22 | Boise | 60.4 | 55 | +| 2025-10-23 | Portland | 54.6 | 70 | +| 2025-10-23 | Seattle | 57.8 | 68 | +| 2025-10-23 | Boise | 62.0 | 58 | + + +If we want to simply retrieve all of the data from the table, we could run the following query: + +```sql +SELECT * FROM weather_readings; +``` + +Result: + +``` +date place temperature humidity +---------- -------- ----------- -------- +2025-10-22 Portland 53.1 72 +2025-10-22 Seattle 56.2 66 +2025-10-22 Boise 60.4 55 +2025-10-23 Portland 54.6 70 +2025-10-23 Seattle 57.8 68 +2025-10-23 Boise 62.0 58 +``` + +But if we only want the place and temperature values, we could specify those columns: + +```sql +SELECT place, temperature FROM weather_readings; +``` + +Result: + +``` +place temperature +-------- ----------- +Portland 53.1 +Seattle 56.2 +Boise 60.4 +Portland 54.6 +Seattle 57.8 +Boise 62.0 +``` + + +Note that 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 weather data for Seattle: + +```sql +SELECT * FROM weather_readings +WHERE place = "Seattle"; +``` + +Result: +``` +date place temperature humidity +---------- -------- ----------- -------- +2025-10-22 Seattle 56.2 66 +2025-10-23 Seattle 57.8 68 +``` + + +Or maybe we only want data where the humidity is between 60 and 70: + +```sql +SELECT * FROM weather_readings +WHERE humidity BETWEEN 60 AND 70; +``` + + +Result: +``` +date place temperature humidity +---------- -------- ----------- -------- +2025-10-22 Seattle 56.2 66 +2025-10-23 Seattle 57.8 68 +2025-10-23 Portland 54.6 70 +``` + + +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](https://sqlite.org/lang_expr.html) for the complete documentation. + + +## Handling duplicate data + +Sometimes it is useful to filter out duplicate items in the output data. For example, let's say we +want to get a list of all the cities for which we have readings. If we run the following query + +```sql +SELECT place FROM weather_readings; +``` + +we would get the following result: + +``` +place +-------- +Portland +Seattle +Boise +Portland +Seattle +Boise +``` + +By using the `DISTINCT` keyword in our query, we can reduce the result to the set of unique place names: + +```sql +SELECT DISTINCT place FROM weather_readings; +``` + +``` +place +-------- +Portland +Seattle +Boise +``` diff --git a/concepts/select/introduction.md b/concepts/select/introduction.md new file mode 100644 index 00000000..7689ef68 --- /dev/null +++ b/concepts/select/introduction.md @@ -0,0 +1,4 @@ +# Introduction + +The SQL `SELECT` statement is the mechanism for querying -- retrieving data from -- a database. The result of a `SELECT` statement is a dataset -- 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. With a `SELECT` statement, you can specify the data you want and optionally transform, filter, and/or modify the shape of the output data. + diff --git a/concepts/select/links.json b/concepts/select/links.json new file mode 100644 index 00000000..58fcb18f --- /dev/null +++ b/concepts/select/links.json @@ -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" + } +] From 1ce3730095082cd2dee615097fa7cad5dfbb2550 Mon Sep 17 00:00:00 2001 From: Todd Schwartz Date: Sat, 25 Oct 2025 17:19:41 -0700 Subject: [PATCH 2/5] Add entry to config.json; add .meta/config.json --- concepts/select/.meta/config.json | 5 +++++ config.json | 7 +++++++ 2 files changed, 12 insertions(+) create mode 100644 concepts/select/.meta/config.json diff --git a/concepts/select/.meta/config.json b/concepts/select/.meta/config.json new file mode 100644 index 00000000..5c83a855 --- /dev/null +++ b/concepts/select/.meta/config.json @@ -0,0 +1,5 @@ +{ + "blurb": "The SQL SELECT statement is the mechanism for querying a database.", + "authors": ["blackk-foxx"], + "contributors": ["blackk-foxx"] +} \ No newline at end of file diff --git a/config.json b/config.json index 4ecaaded..18b81076 100644 --- a/config.json +++ b/config.json @@ -716,6 +716,13 @@ "icon": "small" } ], + "concepts": [ + { + "uuid": "92187df0-fb68-4b46-af3b-cc17c2ef6fbc", + "slug": "select", + "name": "SELECT" + } + ], "tags": [ "execution_mode/interpreted", "platform/linux", From 97970db3c9e0a9c773d52ec20ac6fb96bfe1f269 Mon Sep 17 00:00:00 2001 From: Todd Schwartz Date: Sun, 26 Oct 2025 08:04:52 -0700 Subject: [PATCH 3/5] Address review feedback --- concepts/select/.meta/config.json | 2 +- concepts/select/about.md | 44 ++++---- concepts/select/introduction.md | 165 +++++++++++++++++++++++++++++- 3 files changed, 189 insertions(+), 22 deletions(-) diff --git a/concepts/select/.meta/config.json b/concepts/select/.meta/config.json index 5c83a855..5442fc00 100644 --- a/concepts/select/.meta/config.json +++ b/concepts/select/.meta/config.json @@ -2,4 +2,4 @@ "blurb": "The SQL SELECT statement is the mechanism for querying a database.", "authors": ["blackk-foxx"], "contributors": ["blackk-foxx"] -} \ No newline at end of file +} diff --git a/concepts/select/about.md b/concepts/select/about.md index d4d92d34..b79142c7 100644 --- a/concepts/select/about.md +++ b/concepts/select/about.md @@ -1,6 +1,7 @@ # The SELECT statement -When you want to retrieve data from a database, you issue a query. In SQL, you issue a query using the `SELECT` statement. The result of a `SELECT` statement is a dataset -- 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. +In SQL, a `SELECT` statement allows you to retrieve data from a database. +The result of a `SELECT` statement is a dataset -- 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. @@ -20,12 +21,14 @@ WHERE ; 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. +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 `weather_readings` containing the following data: -| date | place | temperature | humidity | +| date | location | temperature | humidity | |------------|--------------|-------------|----------| | 2025-10-22 | Portland | 53.1 | 72 | | 2025-10-22 | Seattle | 56.2 | 66 | @@ -44,7 +47,7 @@ SELECT * FROM weather_readings; Result: ``` -date place temperature humidity +date location temperature humidity ---------- -------- ----------- -------- 2025-10-22 Portland 53.1 72 2025-10-22 Seattle 56.2 66 @@ -54,16 +57,16 @@ date place temperature humidity 2025-10-23 Boise 62.0 58 ``` -But if we only want the place and temperature values, we could specify those columns: +But if we only want the location and temperature values, we could specify those columns: ```sql -SELECT place, temperature FROM weather_readings; +SELECT location, temperature FROM weather_readings; ``` Result: ``` -place temperature +location temperature -------- ----------- Portland 53.1 Seattle 56.2 @@ -74,7 +77,8 @@ Boise 62.0 ``` -Note that the `FROM` clause is optional. A statement like `SELECT "Hello, world.";` is perfectly valid, and will generate the following result: +Note that the `FROM` clause is optional. +A statement like `SELECT "Hello, world.";` is perfectly valid, and will generate the following result: ``` "Hello, world." @@ -89,12 +93,12 @@ For example, if we only want weather data for Seattle: ```sql SELECT * FROM weather_readings -WHERE place = "Seattle"; +WHERE location = "Seattle"; ``` Result: ``` -date place temperature humidity +date location temperature humidity ---------- -------- ----------- -------- 2025-10-22 Seattle 56.2 66 2025-10-23 Seattle 57.8 68 @@ -111,7 +115,7 @@ WHERE humidity BETWEEN 60 AND 70; Result: ``` -date place temperature humidity +date location temperature humidity ---------- -------- ----------- -------- 2025-10-22 Seattle 56.2 66 2025-10-23 Seattle 57.8 68 @@ -119,22 +123,24 @@ date place temperature humidity ``` -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](https://sqlite.org/lang_expr.html) for the complete documentation. +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](https://sqlite.org/lang_expr.html) for the complete documentation. ## Handling duplicate data -Sometimes it is useful to filter out duplicate items in the output data. For example, let's say we -want to get a list of all the cities for which we have readings. If we run the following query +Sometimes it is useful to filter out duplicate items in the output data. +For example, let's say we want to get a list of all the cities for which we have readings. +If we run the following query: ```sql -SELECT place FROM weather_readings; +SELECT location FROM weather_readings; ``` we would get the following result: ``` -place +location -------- Portland Seattle @@ -144,14 +150,14 @@ Seattle Boise ``` -By using the `DISTINCT` keyword in our query, we can reduce the result to the set of unique place names: +By using the `DISTINCT` keyword in our query, we can reduce the result to the set of unique location names: ```sql -SELECT DISTINCT place FROM weather_readings; +SELECT DISTINCT location FROM weather_readings; ``` ``` -place +location -------- Portland Seattle diff --git a/concepts/select/introduction.md b/concepts/select/introduction.md index 7689ef68..b79142c7 100644 --- a/concepts/select/introduction.md +++ b/concepts/select/introduction.md @@ -1,4 +1,165 @@ -# Introduction +# The SELECT statement -The SQL `SELECT` statement is the mechanism for querying -- retrieving data from -- a database. The result of a `SELECT` statement is a dataset -- 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. With a `SELECT` statement, you can specify the data you want and optionally transform, filter, and/or modify the shape of the output data. +In SQL, a `SELECT` statement allows you to retrieve data from a database. +The result of a `SELECT` statement is a dataset -- 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 +FROM +WHERE ; +``` + +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 `weather_readings` containing the following data: + + +| date | location | temperature | humidity | +|------------|--------------|-------------|----------| +| 2025-10-22 | Portland | 53.1 | 72 | +| 2025-10-22 | Seattle | 56.2 | 66 | +| 2025-10-22 | Boise | 60.4 | 55 | +| 2025-10-23 | Portland | 54.6 | 70 | +| 2025-10-23 | Seattle | 57.8 | 68 | +| 2025-10-23 | Boise | 62.0 | 58 | + + +If we want to simply retrieve all of the data from the table, we could run the following query: + +```sql +SELECT * FROM weather_readings; +``` + +Result: + +``` +date location temperature humidity +---------- -------- ----------- -------- +2025-10-22 Portland 53.1 72 +2025-10-22 Seattle 56.2 66 +2025-10-22 Boise 60.4 55 +2025-10-23 Portland 54.6 70 +2025-10-23 Seattle 57.8 68 +2025-10-23 Boise 62.0 58 +``` + +But if we only want the location and temperature values, we could specify those columns: + +```sql +SELECT location, temperature FROM weather_readings; +``` + +Result: + +``` +location temperature +-------- ----------- +Portland 53.1 +Seattle 56.2 +Boise 60.4 +Portland 54.6 +Seattle 57.8 +Boise 62.0 +``` + + +Note that 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 weather data for Seattle: + +```sql +SELECT * FROM weather_readings +WHERE location = "Seattle"; +``` + +Result: +``` +date location temperature humidity +---------- -------- ----------- -------- +2025-10-22 Seattle 56.2 66 +2025-10-23 Seattle 57.8 68 +``` + + +Or maybe we only want data where the humidity is between 60 and 70: + +```sql +SELECT * FROM weather_readings +WHERE humidity BETWEEN 60 AND 70; +``` + + +Result: +``` +date location temperature humidity +---------- -------- ----------- -------- +2025-10-22 Seattle 56.2 66 +2025-10-23 Seattle 57.8 68 +2025-10-23 Portland 54.6 70 +``` + + +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](https://sqlite.org/lang_expr.html) for the complete documentation. + + +## Handling duplicate data + +Sometimes it is useful to filter out duplicate items in the output data. +For example, let's say we want to get a list of all the cities for which we have readings. +If we run the following query: + +```sql +SELECT location FROM weather_readings; +``` + +we would get the following result: + +``` +location +-------- +Portland +Seattle +Boise +Portland +Seattle +Boise +``` + +By using the `DISTINCT` keyword in our query, we can reduce the result to the set of unique location names: + +```sql +SELECT DISTINCT location FROM weather_readings; +``` + +``` +location +-------- +Portland +Seattle +Boise +``` From f430f976bf941d68ea621141883a587dc18c4eff Mon Sep 17 00:00:00 2001 From: Todd Schwartz Date: Sun, 26 Oct 2025 11:43:11 -0700 Subject: [PATCH 4/5] Align with Exercism markdown style guide --- concepts/select/about.md | 9 ++++++--- concepts/select/introduction.md | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/concepts/select/about.md b/concepts/select/about.md index b79142c7..f22f8b15 100644 --- a/concepts/select/about.md +++ b/concepts/select/about.md @@ -76,8 +76,8 @@ Seattle 57.8 Boise 62.0 ``` - -Note that the `FROM` clause is optional. +~~~~exercism/note +The `FROM` clause is optional. A statement like `SELECT "Hello, world.";` is perfectly valid, and will generate the following result: ``` @@ -85,6 +85,7 @@ A statement like `SELECT "Hello, world.";` is perfectly valid, and will generate --------------- Hello, world. ``` +~~~~ ## Filtering data with the WHERE clause @@ -124,7 +125,7 @@ date location temperature humidity 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](https://sqlite.org/lang_expr.html) for the complete documentation. +See [SQL Language Expressions](sql-expr) for the complete documentation. ## Handling duplicate data @@ -163,3 +164,5 @@ Portland Seattle Boise ``` + +[sql-expr]: https://sqlite.org/lang_expr.html diff --git a/concepts/select/introduction.md b/concepts/select/introduction.md index b79142c7..f22f8b15 100644 --- a/concepts/select/introduction.md +++ b/concepts/select/introduction.md @@ -76,8 +76,8 @@ Seattle 57.8 Boise 62.0 ``` - -Note that the `FROM` clause is optional. +~~~~exercism/note +The `FROM` clause is optional. A statement like `SELECT "Hello, world.";` is perfectly valid, and will generate the following result: ``` @@ -85,6 +85,7 @@ A statement like `SELECT "Hello, world.";` is perfectly valid, and will generate --------------- Hello, world. ``` +~~~~ ## Filtering data with the WHERE clause @@ -124,7 +125,7 @@ date location temperature humidity 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](https://sqlite.org/lang_expr.html) for the complete documentation. +See [SQL Language Expressions](sql-expr) for the complete documentation. ## Handling duplicate data @@ -163,3 +164,5 @@ Portland Seattle Boise ``` + +[sql-expr]: https://sqlite.org/lang_expr.html From f5453962f5c864250f71e3b1315c5e43100bf765 Mon Sep 17 00:00:00 2001 From: Todd Schwartz Date: Mon, 27 Oct 2025 08:20:57 -0700 Subject: [PATCH 5/5] Address review feedback - Replace "dataset" with "result set" - Remove DISTINCT --- concepts/select/about.md | 39 +-------------------------------- concepts/select/introduction.md | 39 +-------------------------------- 2 files changed, 2 insertions(+), 76 deletions(-) diff --git a/concepts/select/about.md b/concepts/select/about.md index f22f8b15..9e12d8de 100644 --- a/concepts/select/about.md +++ b/concepts/select/about.md @@ -1,7 +1,7 @@ # The SELECT statement In SQL, a `SELECT` statement allows you to retrieve data from a database. -The result of a `SELECT` statement is a dataset -- 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. +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. @@ -128,41 +128,4 @@ In addition to `=` and `BETWEEN...AND`, the `WHERE` clause supports a wide range See [SQL Language Expressions](sql-expr) for the complete documentation. -## Handling duplicate data - -Sometimes it is useful to filter out duplicate items in the output data. -For example, let's say we want to get a list of all the cities for which we have readings. -If we run the following query: - -```sql -SELECT location FROM weather_readings; -``` - -we would get the following result: - -``` -location --------- -Portland -Seattle -Boise -Portland -Seattle -Boise -``` - -By using the `DISTINCT` keyword in our query, we can reduce the result to the set of unique location names: - -```sql -SELECT DISTINCT location FROM weather_readings; -``` - -``` -location --------- -Portland -Seattle -Boise -``` - [sql-expr]: https://sqlite.org/lang_expr.html diff --git a/concepts/select/introduction.md b/concepts/select/introduction.md index f22f8b15..9e12d8de 100644 --- a/concepts/select/introduction.md +++ b/concepts/select/introduction.md @@ -1,7 +1,7 @@ # The SELECT statement In SQL, a `SELECT` statement allows you to retrieve data from a database. -The result of a `SELECT` statement is a dataset -- 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. +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. @@ -128,41 +128,4 @@ In addition to `=` and `BETWEEN...AND`, the `WHERE` clause supports a wide range See [SQL Language Expressions](sql-expr) for the complete documentation. -## Handling duplicate data - -Sometimes it is useful to filter out duplicate items in the output data. -For example, let's say we want to get a list of all the cities for which we have readings. -If we run the following query: - -```sql -SELECT location FROM weather_readings; -``` - -we would get the following result: - -``` -location --------- -Portland -Seattle -Boise -Portland -Seattle -Boise -``` - -By using the `DISTINCT` keyword in our query, we can reduce the result to the set of unique location names: - -```sql -SELECT DISTINCT location FROM weather_readings; -``` - -``` -location --------- -Portland -Seattle -Boise -``` - [sql-expr]: https://sqlite.org/lang_expr.html