简体   繁体   English

过滤时不明确的列名“已删除”

[英]Ambiguous column name 'DELETED' when filtering

Good morning.早上好。

Without saying to much, I am joining two tables where each contain a row with the same name field DELETED.不用多说,我将加入两个表,每个表都包含一行具有相同名称的字段已删除。 I am able to join both tables and get results, the problem is when I try to filter out those orders that are DELETED "X" and not DELETED "NULL", I get the ambiguous column name.我能够加入两个表并获得结果,问题是当我尝试过滤掉那些被删除的“X”而不是“NULL”的订单时,我得到了不明确的列名。

SELECT

OCRI.DDORD#,
OCRH.DCBCUS,
OCRI.DELETED

from ocri
join OCRH on DCORD# = DDORD#    
where OCRI.dditst <> 'C'
and DELETED <> 'X'

I have tried and OCRI.DELETED <> 'X' but then I get no results.我已经尝试过 OCRI.DELETED <> 'X' 但我没有得到任何结果。

I would like to be able to filter out the X我希望能够过滤掉 X

DDORD#  DCBCUS     DELETED
194991  150482      NULL
195000  263609      X
195381  263609      X
195387  246045      NULL
195724  146551      NULL

Qualify ALL column references in your query.限定查询中的所有列引用。 You haven't provided enough information to know which columns belong where.您没有提供足够的信息来了解哪些列属于哪里。

Then, you need to handle NULL values.然后,您需要处理NULL值。

An example:一个例子:

SELECT rh.DDORD#, ri.DCBCUS, ri.DELETED
FROM ocri ri JOIN
     OCRH rh
     ON ri.DCORD# = rh.DDORD#    
WHERE rh.rhdditst <> 'C' AND
      (ri.DELETED <> 'X' OR ri.DELETED IS NULL);

Of course, I don't know what the tables look like so the qualifications are probably wrong.当然,我不知道表格是什么样子的,所以资格可能是错误的。

Note that standard SQL has a NULL -safe comparison, which is supported by some databases.请注意,标准 SQL 具有NULL比较,某些数据库支持该比较。 This looks like:这看起来像:

WHERE rh.rhdditst <> 'C' AND
      ri.DELETED IS DISTINCT FROM 'X';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM