OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Resources

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS

OceanBase Cloud

OceanBase Database

Tools

Connectors and Middleware

QUICK START

OceanBase Cloud

OceanBase Database

BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Company

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

International - English
中国站 - 简体中文
日本 - 日本語
Sign In
Start on Cloud

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS
OceanBase CloudOceanBase Database
ToolsConnectors and Middleware
QUICK START
OceanBase CloudOceanBase Database
BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

Start on Cloud
编组
All Products
    • Databases
    • iconOceanBase Database
    • iconOceanBase Cloud
    • iconOceanBase Tugraph
    • iconInteractive Tutorials
    • iconOceanBase Best Practices
    • Tools
    • iconOceanBase Cloud Platform
    • iconOceanBase Migration Service
    • iconOceanBase Developer Center
    • iconOceanBase Migration Assessment
    • iconOceanBase Admin Tool
    • iconOceanBase Loader and Dumper
    • iconOceanBase Deployer
    • iconKubernetes operator for OceanBase
    • iconOceanBase Diagnostic Tool
    • iconOceanBase Binlog Service
    • Connectors and Middleware
    • iconOceanBase Database Proxy
    • iconEmbedded SQL in C for OceanBase
    • iconOceanBase Call Interface
    • iconOceanBase Connector/C
    • iconOceanBase Connector/J
    • iconOceanBase Connector/ODBC
    • iconOceanBase Connector/NET
icon

OceanBase Database

SQL - V4.3.3

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogWhite PaperLive DemosTraining & CertificationTicket
    Company
    About OceanBaseTrust CenterLegalPartnerContact Us
    Follow Us

    © OceanBase 2026. All rights reserved

    Cloud Service AgreementPrivacy PolicySecurity
    Contact Us
    Document Feedback
    1. Documentation Center
    2. OceanBase Database
    3. SQL
    4. V4.3.3
    iconOceanBase Database
    SQL - V 4.3.3
    Databases
    • OceanBase Database
    • OceanBase Cloud
    • OceanBase Tugraph
    • Interactive Tutorials
    • OceanBase Best Practices
    Tools
    • OceanBase Cloud Platform
    • OceanBase Migration Service
    • OceanBase Developer Center
    • OceanBase Migration Assessment
    • OceanBase Admin Tool
    • OceanBase Loader and Dumper
    • OceanBase Deployer
    • Kubernetes operator for OceanBase
    • OceanBase Diagnostic Tool
    • OceanBase Binlog Service
    Connectors and Middleware
    • OceanBase Database Proxy
    • Embedded SQL in C for OceanBase
    • OceanBase Call Interface
    • OceanBase Connector/C
    • OceanBase Connector/J
    • OceanBase Connector/ODBC
    • OceanBase Connector/NET
    SQL
    KV
    • V 4.6.0
    • V 4.4.2
    • V 4.3.5
    • V 4.3.3
    • V 4.3.1
    • V 4.3.0
    • V 4.2.5
    • V 4.2.2
    • V 4.2.1
    • V 4.2.0
    • V 4.1.0
    • V 4.0.0
    • V 3.1.4 and earlier

    JOIN clause

    Last Updated:2025-11-27 02:38:06  Updated
    Share
    What is on this page
    Purpose
    Syntax
    Parameters
    Examples

    folded

    Share

    Purpose

    You can use the JOIN clause to join tables.

    A join statement is used in the database to combine two or more tables in the database based on the join conditions. The set generated by a join can be saved as a table or used as a table. A join statement combines the attributes of two tables based on their values.

    Syntax

    table_references:
        table_reference [, table_reference ...]
    
    table_reference:
        table_factor
      | joined_table
    
    table_factor:
        table_name [partition_option]
     [[AS] alias] [index_hint_list]
      | table_subquery [AS] alias
      | ( table_references )
    
    joined_table:
          table_reference [NATURAL] [[INNER] | CROSS] JOIN table_factor [join_condition]
        | table_reference outer_join_type JOIN table_factor join_condition
    
    partition_option:
        PARTITION (partition_name_list)
    
    join_condition:
         ON expression
       | USING (join_column_list)
    
    join_column_list:
        column_name [, column_name ...]
    
    outer_join_type:
        [NATURAL] {LEFT | RIGHT | FULL} [OUTER]
    
    index_hint_list:
        index_hint [, index_hint ...]
    
    index_hint:
        {USE | FORCE | IGNORE} {KEY | INDEX}
           [FOR {JOIN | ORDER BY | GROUP BY}] (index_list)
    
    index_list:
        index_name [, index_name ...]
    

    Parameters

    Parameter
    Description
    PARTITION (partition_name_list) The table partitions to be joined.
    NATURAL Indicates a natural join. NATURAL JOIN automatically joins the same columns.
    [INNER] JOIN Indicates an inner join. When no join condition is specified, INNER JOIN is equivalent to a comma (,). Both of them generate a Cartesian product by using the specified tables.
    Notice The comma (,) as an operator has a lower priority than INNER JOIN, CROSS JOIN, and LEFT JOIN. Therefore, if you use commas (,) with other join keywords, the condition of the ON clause may be invalid.
    CROSS JOIN In the MySQL mode of OceanBase Database, CROSS JOIN is equivalent to JOIN and INNER JOIN.
    LEFT [OUTER] JOIN Indicates a left outer join. If a row in the table on the left side is not found in the table on the right side, NULL is automatically filled in the join result for the table on the right side.
    RIGHT [OUTER] JOIN Indicates a right outer join. If a row in the table on the right side is not found in the table on the left side, NULL is automatically filled in the join result for the table on the left side.
    FULL [OUTER] JOIN Indicates a full join. NULL is automatically filled in the join result if no matching row is found in the table on the left or right side.
    column_name The name of the column used for joining.
    index_hint Specifies whether to use the specified index for the query.
    • USE: specifies to use an index for a specific operation.
    • FORCE: specifies to forcibly use indexes for some operations.
    • IGNORE: specifies not to use indexes for a specific operation.
    • FOR JOIN: specifies to join indexes.
    • FOR ORDER BY: specifies to sort indexes.
    • FOR GROUP BY: specifies to group indexes.
    ON expression A join condition that returns duplicate columns. This clause is applicable when columns with different names are used as join condition.
    USING (join_column_list) A join condition that does not return duplicate columns. This clause is applicable only when columns with the same name in the tables to be joined are used as the join condition.

    Examples

    Take the a and b tables as an example.

    Join

    • Perform an inner join on the a and b tables.

      obclient> SELECT * FROM a JOIN b ON a.ID=b.ID;
      +------+------+------+------+
      | id   | name | id   | num  |
      +------+------+------+------+
      |    1 | A    |    1 |  100 |
      |    3 | A    |    3 |   75 |
      +------+------+------+------+
      2 rows in set
      
    • Perform a cross join on the a and b tables.

      obclient> SELECT * FROM a CROSS JOIN b ON a.id=b.id;
      +------+------+------+------+
      | id   | name | id   | num  |
      +------+------+------+------+
      |    1 | A    |    1 |  100 |
      |    3 | A    |    3 |   75 |
      +------+------+------+------+
      2 rows in set
      
    • Perform a natural join on the a and b tables.

      obclient> SELECT * FROM a NATURAL JOIN b;
      Empty set
      
    • Perform a left outer join on the a and b tables.

      obclient> SELECT * FROM a LEFT JOIN b USING(ID);
      +------+------+------+
      | id   | name | num  |
      +------+------+------+
      |    1 | A    |  100 |
      |    2 | B    | NULL |
      |    3 | A    |   75 |
      +------+------+------+
      3 rows in set
      
    • Perform a right outer join on the a and b tables.

      obclient> SELECT * FROM a RIGHT JOIN b USING(ID);
      +------+------+------+
      | id   | num  | name |
      +------+------+------+
      |    1 |  100 | A    |
      |    3 |   75 | A    |
      |    4 |   50 | NULL |
      +------+------+------+
      3 rows in set
      
    • Perform a full join on the a and b tables.

      obclient> SELECT * FROM a FULL JOIN b USING(ID);
      +------+------+------+
      | id   | name | num  |
      +------+------+------+
      |    1 | A    |  100 |
      |    2 | B    | NULL |
      |    3 | A    |   75 |
      |    4 | NULL |   50 |
      +------+------+------+
      4 rows in set
      

    Previous topic

    SELECT statement
    Last

    Next topic

    OVER clause
    Next
    What is on this page
    Purpose
    Syntax
    Parameters
    Examples