You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by al...@apache.org on 2025/06/12 22:17:16 UTC

(datafusion) branch main updated: doc: Add SQL examples for SEMI + ANTI Joins (#16316)

This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new 3a371ed6ef doc: Add SQL examples for SEMI + ANTI Joins (#16316)
3a371ed6ef is described below

commit 3a371ed6ef38ba49c036d0b13174e0007455bed0
Author: Jonathan Chen <ch...@gmail.com>
AuthorDate: Thu Jun 12 18:17:11 2025 -0400

    doc: Add SQL examples for SEMI + ANTI Joins (#16316)
    
    * doc: Add SQL examples for SEMI + ANTI Joins
    
    * prettier
    
    * Update docs/source/user-guide/sql/select.md
    
    Co-authored-by: Copilot <17...@users.noreply.github.com>
    
    ---------
    
    Co-authored-by: Copilot <17...@users.noreply.github.com>
---
 docs/source/user-guide/sql/select.md | 74 +++++++++++++++++++++++++++++++-----
 1 file changed, 64 insertions(+), 10 deletions(-)

diff --git a/docs/source/user-guide/sql/select.md b/docs/source/user-guide/sql/select.md
index b2fa0a6305..84aac431a6 100644
--- a/docs/source/user-guide/sql/select.md
+++ b/docs/source/user-guide/sql/select.md
@@ -84,7 +84,7 @@ SELECT a FROM table WHERE a > 10
 
 ## JOIN clause
 
-DataFusion supports `INNER JOIN`, `LEFT OUTER JOIN`, `RIGHT OUTER JOIN`, `FULL OUTER JOIN`, `NATURAL JOIN` and `CROSS JOIN`.
+DataFusion supports `INNER JOIN`, `LEFT OUTER JOIN`, `RIGHT OUTER JOIN`, `FULL OUTER JOIN`, `NATURAL JOIN`, `CROSS JOIN`, `LEFT SEMI JOIN`, `RIGHT SEMI JOIN`, `LEFT ANTI JOIN`, and `RIGHT ANTI JOIN`.
 
 The following examples are based on this table:
 
@@ -102,7 +102,7 @@ select * from x;
 The keywords `JOIN` or `INNER JOIN` define a join that only shows rows where there is a match in both tables.
 
 ```sql
-select * from x inner join x y ON x.column_1 = y.column_1;
+SELECT * FROM x INNER JOIN x y ON x.column_1 = y.column_1;
 +----------+----------+----------+----------+
 | column_1 | column_2 | column_1 | column_2 |
 +----------+----------+----------+----------+
@@ -116,7 +116,7 @@ The keywords `LEFT JOIN` or `LEFT OUTER JOIN` define a join that includes all ro
 is not a match in the right table. When there is no match, null values are produced for the right side of the join.
 
 ```sql
-select * from x left join x y ON x.column_1 = y.column_2;
+SELECT * FROM x LEFT JOIN x y ON x.column_1 = y.column_2;
 +----------+----------+----------+----------+
 | column_1 | column_2 | column_1 | column_2 |
 +----------+----------+----------+----------+
@@ -130,7 +130,7 @@ The keywords `RIGHT JOIN` or `RIGHT OUTER JOIN` define a join that includes all
 is not a match in the left table. When there is no match, null values are produced for the left side of the join.
 
 ```sql
-select * from x right join x y ON x.column_1 = y.column_2;
+SELECT * FROM x RIGHT JOIN x y ON x.column_1 = y.column_2;
 +----------+----------+----------+----------+
 | column_1 | column_2 | column_1 | column_2 |
 +----------+----------+----------+----------+
@@ -145,7 +145,7 @@ The keywords `FULL JOIN` or `FULL OUTER JOIN` define a join that is effectively
 either side of the join where there is not a match.
 
 ```sql
-select * from x full outer join x y ON x.column_1 = y.column_2;
+SELECT * FROM x FULL OUTER JOIN x y ON x.column_1 = y.column_2;
 +----------+----------+----------+----------+
 | column_1 | column_2 | column_1 | column_2 |
 +----------+----------+----------+----------+
@@ -156,11 +156,11 @@ select * from x full outer join x y ON x.column_1 = y.column_2;
 
 ### NATURAL JOIN
 
-A natural join defines an inner join based on common column names found between the input tables. When no common
-column names are found, it behaves like a cross join.
+A `NATURAL JOIN` defines an inner join based on common column names found between the input tables. When no common
+column names are found, it behaves like a `CROSS JOIN`.
 
 ```sql
-select * from x natural join x y;
+SELECT * FROM x NATURAL JOIN x y;
 +----------+----------+
 | column_1 | column_2 |
 +----------+----------+
@@ -170,11 +170,11 @@ select * from x natural join x y;
 
 ### CROSS JOIN
 
-A cross join produces a cartesian product that matches every row in the left side of the join with every row in the
+A `CROSS JOIN` produces a cartesian product that matches every row in the left side of the join with every row in the
 right side of the join.
 
 ```sql
-select * from x cross join x y;
+SELECT * FROM x CROSS JOIN x y;
 +----------+----------+----------+----------+
 | column_1 | column_2 | column_1 | column_2 |
 +----------+----------+----------+----------+
@@ -182,6 +182,60 @@ select * from x cross join x y;
 +----------+----------+----------+----------+
 ```
 
+### LEFT SEMI JOIN
+
+The `LEFT SEMI JOIN` returns all rows from the left table that have at least one matching row in the right table, and
+projects only the columns from the left table.
+
+```sql
+SELECT * FROM x LEFT SEMI JOIN x y ON x.column_1 = y.column_1;
++----------+----------+
+| column_1 | column_2 |
++----------+----------+
+| 1        | 2        |
++----------+----------+
+```
+
+### RIGHT SEMI JOIN
+
+The `RIGHT SEMI JOIN` returns all rows from the right table that have at least one matching row in the left table, and
+only projects the columns from the right table.
+
+```sql
+SELECT * FROM x RIGHT SEMI JOIN x y ON x.column_1 = y.column_1;
++----------+----------+
+| column_1 | column_2 |
++----------+----------+
+| 1        | 2        |
++----------+----------+
+```
+
+### LEFT ANTI JOIN
+
+The `LEFT ANTI JOIN` returns all rows from the left table that do not have any matching row in the right table, projecting
+only the left table’s columns.
+
+```sql
+SELECT * FROM x LEFT ANTI JOIN x y ON x.column_1 = y.column_1;
++----------+----------+
+| column_1 | column_2 |
++----------+----------+
++----------+----------+
+```
+
+### RIGHT ANTI JOIN
+
+The `RIGHT ANTI JOIN` returns all rows from the right table that do not have any matching row in the left table, projecting
+only the right table’s columns.
+
+```sql
+SELECT * FROM x RIGHT ANTI JOIN x y ON x.column_1 = y.column_1;
++----------+----------+
+| column_1 | column_2 |
++----------+----------+
++----------+----------+
+```
+
 ## GROUP BY clause
 
 Example:


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org