文档

关于 SequoiaDB

快速入门

快速入门之一键清理

安装

基本操作

数据模型

SQL引擎

FileSystem引擎

S3引擎

系统架构

数据库管理

连接器

驱动

参考手册

SequoiaDB Shell方法

操作符

SQL语法

SQL to SequoiaDB 映射表

限制

错误码

故障排除

SAC 管控中心

Web服务

版本信息

left outer join

left outer join 会从左边的集合名(collection1_name)中返回所有的记录,即使在右边的集合名(collection2_name)中没有匹配的记录。

语法

<collection1_name | (select_set1)> as <alias1_name> left outer join <collection2_name | (select_set2)> as <alias2_name> [on condition]

参数

参数名 参数类型 描述 是否必填
collection1_name/collection2_name string 集合名。
select_set1/select_set2 set 结果集。
alias1_name/alias2_name string 别名。
condition expression 集合之间关联条件。

返回值

left outer join 会从左边的集合(collection1_name)那里返回所有的记录,即使在右边的集合(collection2_name)中没有匹配的记录。

示例

  • 集合 foo.persons 中记录如下。

    { "Id_P": 1, "LastName": "Adams", "FirstName": "John", "Address": "Oxford Street", "City": "London" }
    { "Id_P": 2, "LastName": "Bush", "FirstName": "George", "Address": "Fifth Avenue", "City": "New York" }
    { "Id_P": 3, "LastName": "Carter", "FirstName": "Thomas", "Address": "Changan Street", "City": "Beijing" }
  • 集合 foo.orders 中记录如下。

    { "Id_O": 1, "OrderNo": 77895, "Id_P": 3 }
    { "Id_O": 2, "OrderNo": 44678, "Id_P": 3 }
    { "Id_O": 3, "OrderNo": 22456, "Id_P": 1 }
    { "Id_O": 4, "OrderNo": 24562, "Id_P": 1 }
    { "Id_O": 5, "OrderNo": 34764, "Id_P": 65 }
  • 列出所有客户的订单, 如果该用户没有订单信息,则用null替代其订单信息。

    > db.exec("select t1.LastName, t1.FirstName, t2.OrderNo from foo.persons as t1 left outer  join foo.orders as t2 on t1.Id_P=t2.Id_P")
    { "LastName": "Adams", "FirstName": "John", "OrderNo": 22456 }
    { "LastName": "Adams", "FirstName": "John", "OrderNo": 24562 }
    { "LastName": "Bush", "FirstName": "George", "OrderNo": null }
    { "LastName": "Carter", "FirstName": "Thomas", "OrderNo": 77895 }
    { "LastName": "Carter", "FirstName": "Thomas", "OrderNo": 44678 }
    Return 5 row(s).
    Takes 0.11811s.
回到顶部