From 687e53c50f7e0fe826b1db07eb6879689d6175ae Mon Sep 17 00:00:00 2001 From: saldanhad Date: Wed, 11 Sep 2024 23:03:15 +0530 Subject: [PATCH 1/7] Add concept entry doc for similar to --- .../operators/terms/similar-to/similar-to.md | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 content/sql/concepts/operators/terms/similar-to/similar-to.md diff --git a/content/sql/concepts/operators/terms/similar-to/similar-to.md b/content/sql/concepts/operators/terms/similar-to/similar-to.md new file mode 100644 index 00000000000..69d573fcb9c --- /dev/null +++ b/content/sql/concepts/operators/terms/similar-to/similar-to.md @@ -0,0 +1,88 @@ +--- +Title: 'SIMILAR TO' +Description: 'Similar to `LIKE` operator in SQL' +Subjects: + - 'Data Science' + - 'Computer Science' +Tags: + - 'Operators' + - 'Database' + - 'Queries' + - 'PostgreSQL' +CatalogContent: + - 'learn-sql' + - 'paths/analyze-data-with-sql' +--- + +The **`SIMILAR TO`** operator is primarily found in `PostgreSQL`. The `SIMILAR TO` operator returns true if its pattern matches the given string otherwise returns false. It is similar to `LIKE` operator that is used in other database like SQL Server, MySQL, Oracle SQL, and supports pattern matching via the use of [wildcards](https://www.codecademy.com/resources/docs/sql/wildcards). + +## Syntax + +`SIMILAR TO` is typically used conditionally with a `WHERE` clause to select rows based on a column matching a given string pattern. + +```pseudo +SELECT * +FROM table_name +WHERE column_name SIMILAR TO pattern; +``` + +The `pattern` here constitutes a string that includes the following wildcards: + +- `%` Matches zero or more arbitrary characters. +- `_` Matches exactly one arbitrary character. + + +## Example 1 + +```sql +SELECT * +FROM countries +WHERE country_name SIMILAR TO 'M%'; +``` + +Explanation: + +- `M`: The name must start with the letter "M". +- `%`: Matches zero or more characters after "M". + +Example Matches: + +- Mexico +- Malaysia + +## Example 2 + +```sql +SELECT * +FROM employees +WHERE name SIMILAR TO '(John|Jane)%'; +``` +Explanation: + +- `(John|Jane)`: The name must start with either "John" or "Jane". +- `%`: Matches zero or more characters after "John" or "Jane". + +Example Matches: + +- Johnathan +- John Smith + +## Example 3 + +```sql +SELECT * +FROM employees +WHERE name SIMILAR TO '(John|Jane)_[A-Z].%'; +``` +Explanation: + +- `(John|Jane)`: The name must start with either "John" or "Jane". +- `_`: Matches exactly one arbitrary character (in this case, a space or any other single character). +- `[A-Z]`: Matches a single uppercase letter, representing a middle initial. +- `.`: Matches a literal period (used after the middle initial). +- `%`: Matches zero or more characters after the period, such as a last name or other additional characters. + +Example Matches: + +- John A. Smith +- Jane B. Doe From 2e49a273fe24678d894da95c0d169d6639ae65ed Mon Sep 17 00:00:00 2001 From: saldanhad Date: Thu, 12 Sep 2024 02:55:29 +0530 Subject: [PATCH 2/7] Update markdown linting issues for similar-to.md --- .../operators/terms/similar-to/similar-to.md | 177 +++++++++--------- 1 file changed, 89 insertions(+), 88 deletions(-) diff --git a/content/sql/concepts/operators/terms/similar-to/similar-to.md b/content/sql/concepts/operators/terms/similar-to/similar-to.md index 69d573fcb9c..a1919bb56df 100644 --- a/content/sql/concepts/operators/terms/similar-to/similar-to.md +++ b/content/sql/concepts/operators/terms/similar-to/similar-to.md @@ -1,88 +1,89 @@ ---- -Title: 'SIMILAR TO' -Description: 'Similar to `LIKE` operator in SQL' -Subjects: - - 'Data Science' - - 'Computer Science' -Tags: - - 'Operators' - - 'Database' - - 'Queries' - - 'PostgreSQL' -CatalogContent: - - 'learn-sql' - - 'paths/analyze-data-with-sql' ---- - -The **`SIMILAR TO`** operator is primarily found in `PostgreSQL`. The `SIMILAR TO` operator returns true if its pattern matches the given string otherwise returns false. It is similar to `LIKE` operator that is used in other database like SQL Server, MySQL, Oracle SQL, and supports pattern matching via the use of [wildcards](https://www.codecademy.com/resources/docs/sql/wildcards). - -## Syntax - -`SIMILAR TO` is typically used conditionally with a `WHERE` clause to select rows based on a column matching a given string pattern. - -```pseudo -SELECT * -FROM table_name -WHERE column_name SIMILAR TO pattern; -``` - -The `pattern` here constitutes a string that includes the following wildcards: - -- `%` Matches zero or more arbitrary characters. -- `_` Matches exactly one arbitrary character. - - -## Example 1 - -```sql -SELECT * -FROM countries -WHERE country_name SIMILAR TO 'M%'; -``` - -Explanation: - -- `M`: The name must start with the letter "M". -- `%`: Matches zero or more characters after "M". - -Example Matches: - -- Mexico -- Malaysia - -## Example 2 - -```sql -SELECT * -FROM employees -WHERE name SIMILAR TO '(John|Jane)%'; -``` -Explanation: - -- `(John|Jane)`: The name must start with either "John" or "Jane". -- `%`: Matches zero or more characters after "John" or "Jane". - -Example Matches: - -- Johnathan -- John Smith - -## Example 3 - -```sql -SELECT * -FROM employees -WHERE name SIMILAR TO '(John|Jane)_[A-Z].%'; -``` -Explanation: - -- `(John|Jane)`: The name must start with either "John" or "Jane". -- `_`: Matches exactly one arbitrary character (in this case, a space or any other single character). -- `[A-Z]`: Matches a single uppercase letter, representing a middle initial. -- `.`: Matches a literal period (used after the middle initial). -- `%`: Matches zero or more characters after the period, such as a last name or other additional characters. - -Example Matches: - -- John A. Smith -- Jane B. Doe +--- +Title: 'SIMILAR TO' +Description: 'Similar to `LIKE` operator in SQL' +Subjects: + - 'Data Science' + - 'Computer Science' +Tags: + - 'Operators' + - 'Database' + - 'Queries' + - 'PostgreSQL' +CatalogContent: + - 'learn-sql' + - 'paths/analyze-data-with-sql' +--- + +The **`SIMILAR TO`** operator is primarily found in `PostgreSQL`. The `SIMILAR TO` operator returns true if its pattern matches the given string otherwise returns false. It is similar to `LIKE` operator that is used in other database like SQL Server, MySQL, Oracle SQL, and supports pattern matching via the use of [wildcards](https://www.codecademy.com/resources/docs/sql/wildcards). + +## Syntax + +`SIMILAR TO` is typically used conditionally with a `WHERE` clause to select rows based on a column matching a given string pattern. + +```pseudo +SELECT * +FROM table_name +WHERE column_name SIMILAR TO pattern; +``` + +The `pattern` here constitutes a string that includes the following wildcards: + +- `%` Matches zero or more arbitrary characters. +- `_` Matches exactly one arbitrary character. + +## Example 1 + +```sql +SELECT * +FROM countries +WHERE country_name SIMILAR TO 'M%'; +``` + +Explanation: + +- `M`: The name must start with the letter "M". +- `%`: Matches zero or more characters after "M". + +Example Matches: + +- Mexico +- Malaysia + +## Example 2 + +```sql +SELECT * +FROM employees +WHERE name SIMILAR TO '(John|Jane)%'; +``` + +Explanation: + +- `(John|Jane)`: The name must start with either "John" or "Jane". +- `%`: Matches zero or more characters after "John" or "Jane". + +Example Matches: + +- Johnathan +- John Smith + +## Example 3 + +```sql +SELECT * +FROM employees +WHERE name SIMILAR TO '(John|Jane)_[A-Z].%'; +``` + +Explanation: + +- `(John|Jane)`: The name must start with either "John" or "Jane". +- `_`: Matches exactly one arbitrary character (in this case, a space or any other single character). +- `[A-Z]`: Matches a single uppercase letter, representing a middle initial. +- `.`: Matches a literal period (used after the middle initial). +- `%`: Matches zero or more characters after the period, such as a last name or other additional characters. + +Example Matches: + +- John A. Smith +- Jane B. Doe From 49cb1f23f6835fd51a14a3c0d0b49fc981cf0331 Mon Sep 17 00:00:00 2001 From: saldanhad Date: Sat, 28 Sep 2024 16:48:24 +0530 Subject: [PATCH 3/7] changes post review-1 --- .../operators/terms/similar-to/similar-to.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/content/sql/concepts/operators/terms/similar-to/similar-to.md b/content/sql/concepts/operators/terms/similar-to/similar-to.md index a1919bb56df..f248c6a1ff3 100644 --- a/content/sql/concepts/operators/terms/similar-to/similar-to.md +++ b/content/sql/concepts/operators/terms/similar-to/similar-to.md @@ -1,6 +1,6 @@ --- Title: 'SIMILAR TO' -Description: 'Similar to `LIKE` operator in SQL' +Description: 'Used to compare a string to a regular expression' Subjects: - 'Data Science' - 'Computer Science' @@ -14,7 +14,7 @@ CatalogContent: - 'paths/analyze-data-with-sql' --- -The **`SIMILAR TO`** operator is primarily found in `PostgreSQL`. The `SIMILAR TO` operator returns true if its pattern matches the given string otherwise returns false. It is similar to `LIKE` operator that is used in other database like SQL Server, MySQL, Oracle SQL, and supports pattern matching via the use of [wildcards](https://www.codecademy.com/resources/docs/sql/wildcards). +The **`SIMILAR TO`** operator is primarily found in `PostgreSQL`. The `SIMILAR TO` operator returns `TRUE` if its pattern matches the given string otherwise, it returns `FALSE`. It is similar to the `LIKE` operator that is used in other databases like SQL Server, MySQL, and Oracle SQL, and supports pattern matching via the use of [wildcards](https://www.codecademy.com/resources/docs/sql/wildcards). ## Syntax @@ -28,11 +28,13 @@ WHERE column_name SIMILAR TO pattern; The `pattern` here constitutes a string that includes the following wildcards: -- `%` Matches zero or more arbitrary characters. -- `_` Matches exactly one arbitrary character. +- `%`: Matches zero or more arbitrary characters. +- `_`: Matches exactly one arbitrary character. ## Example 1 +Selects all countries whose names start with "M". + ```sql SELECT * FROM countries @@ -51,6 +53,8 @@ Example Matches: ## Example 2 +Selects employees whose names start with "John" or "Jane". + ```sql SELECT * FROM employees @@ -69,6 +73,8 @@ Example Matches: ## Example 3 +Selects employees named "John" or "Jane" followed by a middle initial and a period. + ```sql SELECT * FROM employees From 31471670bfd52641868943e81425038aec69c9c9 Mon Sep 17 00:00:00 2001 From: saldanhad Date: Sat, 28 Sep 2024 16:49:50 +0530 Subject: [PATCH 4/7] changes post review-1 From e548591435f93eb8a335e2c3d854a508c49ae36e Mon Sep 17 00:00:00 2001 From: shantanu <56212958+cigar-galaxy82@users.noreply.github.com> Date: Sun, 29 Sep 2024 19:14:46 +0530 Subject: [PATCH 5/7] Update similar-to.md --- .../sql/concepts/operators/terms/similar-to/similar-to.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/content/sql/concepts/operators/terms/similar-to/similar-to.md b/content/sql/concepts/operators/terms/similar-to/similar-to.md index f248c6a1ff3..11d4a3b65d1 100644 --- a/content/sql/concepts/operators/terms/similar-to/similar-to.md +++ b/content/sql/concepts/operators/terms/similar-to/similar-to.md @@ -33,7 +33,7 @@ The `pattern` here constitutes a string that includes the following wildcards: ## Example 1 -Selects all countries whose names start with "M". +The below example will select every country from the `countries` starting with `M`. ```sql SELECT * @@ -53,7 +53,7 @@ Example Matches: ## Example 2 -Selects employees whose names start with "John" or "Jane". +The below example selects every `employee` from the `employees` table whose names start with "John" or "Jane". ```sql SELECT * @@ -73,7 +73,7 @@ Example Matches: ## Example 3 -Selects employees named "John" or "Jane" followed by a middle initial and a period. +The below example selects `employees` named "John" or "Jane" followed by a middle initial and a period. ```sql SELECT * From eb3c639335af13cd7a535ed7ee9f1098f0613f80 Mon Sep 17 00:00:00 2001 From: Daksha Deep Date: Tue, 1 Oct 2024 22:20:07 +0530 Subject: [PATCH 6/7] Minor changes --- .../concepts/operators/terms/similar-to/similar-to.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/content/sql/concepts/operators/terms/similar-to/similar-to.md b/content/sql/concepts/operators/terms/similar-to/similar-to.md index 11d4a3b65d1..ae38b193783 100644 --- a/content/sql/concepts/operators/terms/similar-to/similar-to.md +++ b/content/sql/concepts/operators/terms/similar-to/similar-to.md @@ -14,7 +14,7 @@ CatalogContent: - 'paths/analyze-data-with-sql' --- -The **`SIMILAR TO`** operator is primarily found in `PostgreSQL`. The `SIMILAR TO` operator returns `TRUE` if its pattern matches the given string otherwise, it returns `FALSE`. It is similar to the `LIKE` operator that is used in other databases like SQL Server, MySQL, and Oracle SQL, and supports pattern matching via the use of [wildcards](https://www.codecademy.com/resources/docs/sql/wildcards). +The **`SIMILAR TO`** operator is primarily found in `PostgreSQL`. It returns `TRUE` if its pattern matches the given string; otherwise, it returns `FALSE`. This operator is similar to the `LIKE` operator used in other databases, such as SQL Server, MySQL, and Oracle SQL, and supports pattern matching via the use of [wildcards](https://www.codecademy.com/resources/docs/sql/wildcards). ## Syntax @@ -33,7 +33,7 @@ The `pattern` here constitutes a string that includes the following wildcards: ## Example 1 -The below example will select every country from the `countries` starting with `M`. +The following example selects every country from the `countries` table where the name starts with "M": ```sql SELECT * @@ -53,7 +53,7 @@ Example Matches: ## Example 2 -The below example selects every `employee` from the `employees` table whose names start with "John" or "Jane". +The following example selects every `employee` from the `employees` table whose name starts with either `John` or `Jane`: ```sql SELECT * @@ -73,7 +73,8 @@ Example Matches: ## Example 3 -The below example selects `employees` named "John" or "Jane" followed by a middle initial and a period. + +The following example selects `employees` whose name is either `John` or `Jane`, followed by a middle initial and a period: ```sql SELECT * From 24448e0c5eed48c29ec2b00723a6b36b5bd007f6 Mon Sep 17 00:00:00 2001 From: saldanhad Date: Tue, 1 Oct 2024 22:33:34 +0530 Subject: [PATCH 7/7] fix linting --- content/sql/concepts/operators/terms/similar-to/similar-to.md | 1 - 1 file changed, 1 deletion(-) diff --git a/content/sql/concepts/operators/terms/similar-to/similar-to.md b/content/sql/concepts/operators/terms/similar-to/similar-to.md index ae38b193783..cb7d52e8f2a 100644 --- a/content/sql/concepts/operators/terms/similar-to/similar-to.md +++ b/content/sql/concepts/operators/terms/similar-to/similar-to.md @@ -73,7 +73,6 @@ Example Matches: ## Example 3 - The following example selects `employees` whose name is either `John` or `Jane`, followed by a middle initial and a period: ```sql