maropu commented on a change in pull request #28121: [SPARK-31348][SQL][DOCS]
Document Join in SQL Reference
URL: https://github.com/apache/spark/pull/28121#discussion_r404452835
##########
File path: docs/sql-ref-syntax-qry-select-join.md
##########
@@ -18,5 +18,222 @@ license: |
See the License for the specific language governing permissions and
limitations under the License.
---
+### Description
-**This page is under construction**
+A SQL join is used to combine rows from two relations based on join criteria.
The following section describes the overall join syntax and the sub-sections
cover different types of joins along with examples.
+
+### Syntax
+{% highlight sql %}
+
+relation { [ join_type ] JOIN relation [ join_criteria ] | NATURAL join_type
JOIN relation }
+
+{% endhighlight %}
+
+### Parameters
+<dl>
+ <dt><code><em>relation</em></code></dt>
+ <dd>
+ Specifies the relation to be joined.
+ </dd>
+ <dt><code><em>join_type</em></code></dt>
+ <dd>
+ Specifies the join type.<br><br>
+ <b>Syntax:</b><br>
+ <code>
+ [ INNER ]
+ | CROSS
+ | LEFT [ OUTER ]
+ | [ LEFT ] SEMI
+ | RIGHT [ OUTER ]
+ | FULL [ OUTER ]
+ | [ LEFT ] ANTI
+ </code>
+ </dd>
+ <dt><code><em>join_criteria</em></code></dt>
+ <dd>
+ Specifies how the rows from one relation will be combined with the rows of
another relation.<br><br>
+ <b>Syntax:</b>
+ <code>
+ ON boolean_expression | USING ( column_name [ , column_name ... ] )
+ </code> <br><br>
+ <code>boolean_expression</code><br>
+ Specifies an expression with a return type of boolean.
+
+ </dd>
+</dl>
+
+### Join Types
+
+- <b>Inner Join </b><br>
+The inner join is the default join in Spark. It selects rows that have
matching values in both relations.<br><br>
+ <b>Syntax:</b><br>
+ <code>
+ relation [ INNER ] JOIN relation [ join_criteria ]
+ </code>
+
+- <b>Left Join </b><br>
+A left join returns all values from the left relation and the matched values
from the right relation, or appends NULL if there is no match. It is also
referred to as a left outer join.<br><br>
+ <b>Syntax:</b><br>
+ <code>
+ relation LEFT [ OUTER ] JOIN relation [ join_criteria ]
+ </code>
+
+- <b>Right Join </b><br>
+A right join returns all values from the right relation and the matched values
from the left relation, or appends NULL if there is no match. It is also
referred to as a right outer join.<br><br>
+ <b>Syntax:</b><br>
+ <code>
+ relation RIGHT [ OUTER ] JOIN relation [ join_criteria ]
+ </code>
+
+- <b>Full Join </b><br>
+A full join returns all values from both relations, appending NULL values on
the side that does not have a match. It is also referred to as a full outer
join.<br><br>
+ <b>Syntax:</b><br>
+ <code>
+ relation FULL [ OUTER ] JOIN relation [ join_criteria ]
+ </code>
+
+- <b>Cross Join </b><br>
+A cross join returns the Cartesian product of two relations.<br><br>
+ <b>Syntax:</b><br>
+ <code>
+ relation CROSS JOIN relation [ join_criteria ]
+ </code>
+
+- <b>Semi Join </b><br>
+A semi join returns values from the left side of the relation that has a match
with the right. It is also referred to as a left semi join.<br><br>
+ <b>Syntax:</b><br>
+ <code>
+ relation [ LEFT ] SEMI JOIN relation [ join_criteria ]
+ </code>
+
+- <b>Anti Join </b><br>
+An anti join returns values from the left relation that has no match with the
right. It is also referred to as a left anti join.<br><br>
+ <b>Syntax:</b><br>
+ <code>
+ relation [ LEFT ] ANTI JOIN relation [ join_criteria ]
+ </code>
+
+### Examples
+{% highlight sql %}
+-- Use employee and department tables to demonstrate different type of joins.
+SELECT * FROM employee;
+
+ +---+-----+-------+
+ |id |name |deptno |
+ +---+-----+-------+
+ |105|Chloe|5 |
+ |103|Paul |3 |
+ |101|John |1 |
+ |102|Lisa |2 |
+ |104|Evan |4 |
+ |106|Amy |6 |
+ +---+-----+-------+
+
+SELECT * FROM department;
+ +-------+-----------+
+ |deptno |deptname |
+ +-------+-----------+
+ |3 |Engineering|
+ |2 |Sales |
+ |1 |Marketing |
+ +-------+-----------+
+
+-- Use employee and department tables to demonstrate inner join.
+SELECT id, name, employee.deptno, deptname
+ FROM employee INNER JOIN department ON employee.deptno = department.deptno;
Review comment:
Ah, I see. Anything looks fine to me, but I think its better to have
consistency in our SQL docs. How about following 4 spaces?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]