From 40ab45faebbfe7b31a3939a47b58752463476052 Mon Sep 17 00:00:00 2001
From: lizayugabyte <77016159+lizayugabyte@users.noreply.github.com>
Date: Mon, 1 Feb 2021 11:17:09 -0500
Subject: [PATCH 01/10] Added content to queries.md
---
.../explore/ysql-language-features/queries.md | 115 ++++++++++++++++++
1 file changed, 115 insertions(+)
create mode 100644 docs/content/latest/explore/ysql-language-features/queries.md
diff --git a/docs/content/latest/explore/ysql-language-features/queries.md b/docs/content/latest/explore/ysql-language-features/queries.md
new file mode 100644
index 000000000000..769201636331
--- /dev/null
+++ b/docs/content/latest/explore/ysql-language-features/queries.md
@@ -0,0 +1,115 @@
+---
+title: Queries and Joins
+linkTitle: Queries and Joins
+description: Queries and Joins in YSQL
+headcontent: Queries and Joins in YSQL
+image: /images/section_icons/secure/create-roles.png
+menu:
+ latest:
+ identifier: explore-ysql-language-features-queries-joins
+ parent: explore-ysql-language-features
+ weight: 300
+isTocNested: true
+showAsideToc: true
+---
+
+Intro ...
+
+## `SELECT` Statements
+
+The main purpose of `SELECT` statements is to retrieve data from specified tables. The first part of every `SELECT` statement defines columns that contain the required data, the second part points to the tables hosting these columns, and the third, optional part, lists restrictions.
+
+`SELECT` has the following syntax:
+
+```sql
+SELECT list FROM table_name;
+```
+
+*list* represents a column or a list of columns in a *table_name* table that is the subject of data retrieval. If you provide a list of columns, you need to use a comma separator between two columns. To select data from all the columns in the table, you can use an asterisk, as shown in the following example with a table called `employees`:
+
+```sql
+SELECT * FROM employees;
+```
+
+*list* can also contain expressions or literal values.
+
+The following `SELECT` statement clauses enable flexiblity with regards to fine-tuning queries:
+
+- The `DISTINCT` operator allows you to select distinct rows.
+- The `ORDER BY` clause lets you sort rows.
+- The `WHERE` clause allows you to apply filters to rows.
+- The `LIMIT` and `FETCH` clauses allow you to select a subset of rows from a table.
+- The `GROUP BY` clause allows you to divide rows into groups.
+- The `HAVING` clause lets you filter groups.
+- The `INNER JOIN`, `LEFT JOIN`, `FULL OUTER JOIN`, and `CROSS JOIN` clauses let you create joins with other tables.
+- `UNION`, `INTERSECT`, and `EXCEPT` allow you to perform set operations.
+
+
+
+
+
+
+
+
+
+* Aliases with `AS`
+
+* `WHERE` clause and expressions
+
+ * Boolean expressions - `AND` and `OR` clauses
+ * Numeric expressions
+ * Date expressions
+
+* `LIMIT` and `OFFSET`
+
+* `ORDER BY` clause
+
+* `DISTINCT` clause
+
+* `GROUP BY` clause
+
+* `HAVING` clause
+
+
+
+
+
+
+
+
+
+## Joins
+
+
+### Cross Join
+
+
+### Inner Join
+
+
+### Left Outer Join
+
+
+### Right Outer Join
+
+
+### Full Outer Join
+
+
+## Recursive Queries (CTEs)
+
+* Common Table Expressions
+
+## Hierarchical queries
+
+Can be achieved in one of two ways:
+
+* Using common table expressions (CTE)
+* Using the `tablefunc` extension
+
+
+## Miscellaneous queries
+
+### Wildcard matches - `LIKE` clause
+
+### Handling upper and lower case
\ No newline at end of file
From 2ec380e45ad5bc5aef272bc30bc69cbc74810916 Mon Sep 17 00:00:00 2001
From: lizayugabyte <77016159+lizayugabyte@users.noreply.github.com>
Date: Mon, 1 Feb 2021 12:00:47 -0500
Subject: [PATCH 02/10] Added content to queries.md
---
.../latest/explore/ysql-language-features/queries.md | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/docs/content/latest/explore/ysql-language-features/queries.md b/docs/content/latest/explore/ysql-language-features/queries.md
index 769201636331..c5fecfcc23f0 100644
--- a/docs/content/latest/explore/ysql-language-features/queries.md
+++ b/docs/content/latest/explore/ysql-language-features/queries.md
@@ -15,7 +15,7 @@ showAsideToc: true
Intro ...
-## `SELECT` Statements
+## Retrieving Data
The main purpose of `SELECT` statements is to retrieve data from specified tables. The first part of every `SELECT` statement defines columns that contain the required data, the second part points to the tables hosting these columns, and the third, optional part, lists restrictions.
@@ -33,7 +33,9 @@ SELECT * FROM employees;
*list* can also contain expressions or literal values.
-The following `SELECT` statement clauses enable flexiblity with regards to fine-tuning queries:
+The `FROM` clause is evaluated before `SELECT`.
+
+The following `SELECT` statement clauses provide flexiblity and allow you to fine-tune queries:
- The `DISTINCT` operator allows you to select distinct rows.
- The `ORDER BY` clause lets you sort rows.
@@ -44,7 +46,7 @@ The following `SELECT` statement clauses enable flexiblity with regards to fine-
- The `INNER JOIN`, `LEFT JOIN`, `FULL OUTER JOIN`, and `CROSS JOIN` clauses let you create joins with other tables.
- `UNION`, `INTERSECT`, and `EXCEPT` allow you to perform set operations.
-
+#### Examples
From 0519c6f20efb9808fa5d734842954a51da1bcd1b Mon Sep 17 00:00:00 2001
From: lizayugabyte <77016159+lizayugabyte@users.noreply.github.com>
Date: Mon, 1 Feb 2021 13:29:20 -0500
Subject: [PATCH 03/10] edits
---
.../explore/ysql-language-features/queries.md | 38 ++++++++++++++++++-
1 file changed, 37 insertions(+), 1 deletion(-)
diff --git a/docs/content/latest/explore/ysql-language-features/queries.md b/docs/content/latest/explore/ysql-language-features/queries.md
index c5fecfcc23f0..d40f8c5b92f2 100644
--- a/docs/content/latest/explore/ysql-language-features/queries.md
+++ b/docs/content/latest/explore/ysql-language-features/queries.md
@@ -13,7 +13,7 @@ isTocNested: true
showAsideToc: true
---
-Intro ...
+This section describes how to query YugabyteDB using the YSQL `SELECT` statement and its clauses.
## Retrieving Data
@@ -48,6 +48,42 @@ The following `SELECT` statement clauses provide flexiblity and allow you to fin
#### Examples
+Suppose you work with a database that includes the following table:
+
+```sql
+CREATE TABLE employees (
+ employee_no integer,
+ name text,
+ department text
+);
+```
+
+You can use the `SELECT` statement to find names of all employees in the `employees` table. In this case, you apply `SELECT` to one column only, as follows:
+
+```sql
+SELECT name FROM employees;
+```
+
+To retrieve data that includes the employee name and department, you need to query from multiple columns first name, last name and email of customers, you can specify these column names in the `SELECT` clause as shown in the following query:
+
+
+
+If you do not know the order of columns, you have an option of listing them within the `INSERT` statement when adding a new row, as follows:
+
+```sql
+INSERT INTO employees (employee_no, name, department) VALUES (1, 'John Smith', 'Marketing');
+```
+
+You can always view your changes by executing the following command:
+
+```shell
+yugabyte=# \d employees
+```
+
+###
+
+
+
From 0c2c9e0fd76759cdd4a4a7498d71efa5ae1b3779 Mon Sep 17 00:00:00 2001
From: lizayugabyte <77016159+lizayugabyte@users.noreply.github.com>
Date: Mon, 1 Feb 2021 15:56:58 -0500
Subject: [PATCH 04/10] edits
---
docs/content/latest/explore/ysql-language-features/queries.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/content/latest/explore/ysql-language-features/queries.md b/docs/content/latest/explore/ysql-language-features/queries.md
index d40f8c5b92f2..e7aed26ffa63 100644
--- a/docs/content/latest/explore/ysql-language-features/queries.md
+++ b/docs/content/latest/explore/ysql-language-features/queries.md
@@ -64,7 +64,7 @@ You can use the `SELECT` statement to find names of all employees in the `employ
SELECT name FROM employees;
```
-To retrieve data that includes the employee name and department, you need to query from multiple columns first name, last name and email of customers, you can specify these column names in the `SELECT` clause as shown in the following query:
+To retrieve data that includes the employee name and department, you need to query multiple columns. you can specify these column names in the `SELECT` clause as shown in the following query:
From 3400c5407dab395a57fe83fbbcce388c266f8438 Mon Sep 17 00:00:00 2001
From: lizayugabyte <77016159+lizayugabyte@users.noreply.github.com>
Date: Mon, 8 Feb 2021 17:34:32 -0500
Subject: [PATCH 05/10] Added content to queries.md and edited _index.md
---
.../explore/ysql-language-features/_index.md | 4 +-
.../explore/ysql-language-features/queries.md | 821 +++++++++++++++++-
2 files changed, 781 insertions(+), 44 deletions(-)
diff --git a/docs/content/latest/explore/ysql-language-features/_index.md b/docs/content/latest/explore/ysql-language-features/_index.md
index d9784e85adba..c131406f40a3 100644
--- a/docs/content/latest/explore/ysql-language-features/_index.md
+++ b/docs/content/latest/explore/ysql-language-features/_index.md
@@ -36,9 +36,9 @@ This section walks through some of the features in YSQL. If you have worked with
|------------------------------|-----------------------------------------------------------|
| [Basics](databases-schemas-tables/) | SQL shell with `ysqlsh`, users, databases, tables and schemas |
| [Data types](data-types/) | String / numeric / temporal types, `SERIAL` pseudo type, `ENUM`, arrays, and composite types |
+| [Data Manipulation](data-manipulation/) | `INSERT`, `UPDATE`, `DELETE`, `INSERT ... ON CONFLICT` and `RETURNING` clauses |
+| [Queries and Joins](queries/) | Queries, joins, `FROM`, `GROUP BY`, `HAVING` clauses, common table expressions, recursive queries|