Sql Informix多连接

Sql Informix多连接,sql,join,left-join,informix,Sql,Join,Left Join,Informix,我需要修改我的查询以添加其他联接。但是新连接可能需要是左连接。我不知道该怎么做。我正在使用Informix: set query "SELECT DISTINCT x.xfertype,x.app_type,x.service_type,x.lang,x.area_type,x.area_value,x.module,x.field1,x.field2,x.disabled,a.frames,a.allocs,a.term_id,t.term,c.center_id,c.ce

我需要修改我的查询以添加其他联接。但是新连接可能需要是左连接。我不知道该怎么做。我正在使用Informix:

     set    query   "SELECT DISTINCT x.xfertype,x.app_type,x.service_type,x.lang,x.area_type,x.area_value,x.module,x.field1,x.field2,x.disabled,a.frames,a.allocs,a.term_id,t.term,c.center_id,c.center_name,a.message_id,x.field3,x.apn_type,x.global, a.icm, s.group_name "
    append  query   " FROM test_xfertypes AS x, test_allocation AS a, test_terms AS t, test_callcenter AS c"
    append  query   " AND a.xfertype = x.xfertype "
    append  query   " AND a.term_id = t.term_id "
    append  query   " AND t.center_id = c.center_id ";
测试类型x
包含
区域值
(int)

我想将上表与另一个新表
test\u routing\u group左键连接为s


我希望左连接,这样它将返回
s.group\u name,其中x.area\u值位于(s.area\u id)
;如果组名存在,则返回组名,否则返回null。

您需要为此使用标准联接语法。您的查询应该如下所示:

SELECT DISTINCT x.xfertype, x.app_type, x.service_type, x.lang,x.area_type,
       x.area_value, x.module, x.field1, x.field2, x.disabled,
       a.frames, a.allocs, a.term_id,
       t.term,c.center_id, c.center_name,a.message_id, x.field3, x.apn_type,x.global,
       a.icm, s.group_name
FROM test_xfertypes x join
     test_allocation a
     on a.xfertype = x.xfertype join
     test_terms t
     on a.term_id = t.term_id join
     test_callcenter c
     on t.center_id = c.center_id
只需添加以下内容,即可左键联接另一个表:

left outer join test_routing_groups s
on x.area_value IN (s.area_id)

您也可以使用“x.area\u value=s.area\u id”而不是“in”子句。

+1因为这个想法是正确的,但我不喜欢隐藏关键关键字(如JOIN和ON)的布局。我会让这些大写和关键字在FROM下对齐。