我正在运行查询
SELECT LOCATION_OID,UPPER(NAME) AS LOCATION_NAME FROM LOCATION LEFT OUTER JOIN LOCATION_CHILD_LOCATION parent on (parent.LOCATION_OID = LOCATION.LOCATION_OID)
有两个表LOCATION和LOCATION_CHILD_LOCATION,Location有456条记录,location_child_location有4条记录。 location_child_location中的记录使用来自父节点位置表的location_oid进行映射。 为什么这个查询会出错?
答案 0 :(得分:1)
您需要指定您想要LOCATION_OID
的表格,否则分析器会混淆它必须查找哪个表来获取数据。试试这个:
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)
答案 1 :(得分:0)
您必须在LOCATION_OID
子句中的select
前添加表名:
SELECT LOCATION.LOCATION_OID,UPPER(NAME) AS LOCATION_NAME FROM LOCATION LEFT OUTER JOIN LOCATION_CHILD_LOCATION on (parent.LOCATION_OID = LOCATION.LOCATION_OID)
答案 2 :(得分:0)
请尝试以下查询,其中正确提及命名以避免表格中的冲突:
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)
答案 3 :(得分:0)
为每个表使用别名,而不是混合两种方法(使用和不使用别名):
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
希望这会有所帮助。