查询抛出错误; "column ambiguously defined"
Query throwing error; "column ambiguously defined"
我是 运行 查询为
SELECT LOCATION_OID,UPPER(NAME) AS LOCATION_NAME FROM LOCATION LEFT OUTER JOIN LOCATION_CHILD_LOCATION parent on (parent.LOCATION_OID = LOCATION.LOCATION_OID)
有两个table LOCATION和LOCATION_CHILD_LOCATION,Location有456条记录,location_child_location有4条记录。 location_child_location 中的记录映射到来自父级的 location_oid,即位置 table。
为什么此查询会出错?
您必须在 select
子句中的 LOCATION_OID
前面添加 table 名称:
SELECT LOCATION.LOCATION_OID,UPPER(NAME) AS LOCATION_NAME FROM LOCATION LEFT OUTER JOIN LOCATION_CHILD_LOCATION on (parent.LOCATION_OID = LOCATION.LOCATION_OID)
您需要指定要从中获取 LOCATION_OID
的 table,否则分析器会混淆它必须查找哪个 table 来获取数据。试试这个:
SELECT LOCATION.LOCATION_OID,UPPER(NAME) AS LOCATION_NAME
FROM LOCATION LEFT OUTER JOIN LOCATION_CHILD_LOCATION parent
on (parent.LOCATION_OID = LOCATION.LOCATION_OID)
尝试以下查询,其中正确提及命名以避免 Table 命名冲突:
SELECT l.LOCATION_OID,UPPER(NAME) AS LOCATION_NAME
FROM LOCATION as l
LEFT OUTER JOIN LOCATION_CHILD_LOCATION parent on (parent.LOCATION_OID = LOCATION.LOCATION_OID)
为每个表使用别名而不是混合使用这两种方法(使用和不使用别名):
SELECT L.LOCATION_OID
,UPPER(L.NAME) AS LOCATION_NAME
FROM LOCATION L
LEFT OUTER JOIN LOCATION_CHILD_LOCATION P ON P.LOCATION_OID = L.LOCATION_OID
希望这会有所帮助。
我是 运行 查询为
SELECT LOCATION_OID,UPPER(NAME) AS LOCATION_NAME FROM LOCATION LEFT OUTER JOIN LOCATION_CHILD_LOCATION parent on (parent.LOCATION_OID = LOCATION.LOCATION_OID)
有两个table LOCATION和LOCATION_CHILD_LOCATION,Location有456条记录,location_child_location有4条记录。 location_child_location 中的记录映射到来自父级的 location_oid,即位置 table。 为什么此查询会出错?
您必须在 select
子句中的 LOCATION_OID
前面添加 table 名称:
SELECT LOCATION.LOCATION_OID,UPPER(NAME) AS LOCATION_NAME FROM LOCATION LEFT OUTER JOIN LOCATION_CHILD_LOCATION on (parent.LOCATION_OID = LOCATION.LOCATION_OID)
您需要指定要从中获取 LOCATION_OID
的 table,否则分析器会混淆它必须查找哪个 table 来获取数据。试试这个:
SELECT LOCATION.LOCATION_OID,UPPER(NAME) AS LOCATION_NAME
FROM LOCATION LEFT OUTER JOIN LOCATION_CHILD_LOCATION parent
on (parent.LOCATION_OID = LOCATION.LOCATION_OID)
尝试以下查询,其中正确提及命名以避免 Table 命名冲突:
SELECT l.LOCATION_OID,UPPER(NAME) AS LOCATION_NAME
FROM LOCATION as l
LEFT OUTER JOIN LOCATION_CHILD_LOCATION parent on (parent.LOCATION_OID = LOCATION.LOCATION_OID)
为每个表使用别名而不是混合使用这两种方法(使用和不使用别名):
SELECT L.LOCATION_OID
,UPPER(L.NAME) AS LOCATION_NAME
FROM LOCATION L
LEFT OUTER JOIN LOCATION_CHILD_LOCATION P ON P.LOCATION_OID = L.LOCATION_OID
希望这会有所帮助。