1

可能重复:
如何限制 Oracle 查询在排序后返回的行数?

我正在使用就像下面的查询:

SELECT url, title, metadesc FROM (
        SELECT url,title, metadesc, rownum rn FROM (
                SELECT url, title, metadesc FROM web
            )
            WHERE rownum <= 60
    )
    WHERE rn > 50

它适用于单个表,但如果加入我的主查询,即

SELECT name, id, url, title, metadesc
FROM web, emp

然后它给了我错误:

java.sql.SQLException: ORA-00918: column ambiguously defined
4

1 回答 1

1

使用任一别名:

SELECT e.name, e.id, w.url, w.title, w.metadesc
  FROM web w
  JOIN emp e ON w.xx = e.yy

或完整的表名(更详细):

SELECT emp .name, emp .id, web.url, web.title, web.metadesc
  FROM web
  JOIN emp ON web.xx = emp .yy

如果子查询返回具有相同名称的两列,则不能执行以下操作SELECT *

SQL> SELECT * FROM (
  2     SELECT d1.dummy, d2.dummy
  3       FROM dual d1, dual d2
  4  );

ERROR at line 1:
ORA-00918: column ambiguously defined

在这种情况下,在带有别名的子查询中使用不同的列名:

SQL> SELECT * FROM (
  2     SELECT d1.dummy dummy_d1, d2.dummy dummy_d2
  3       FROM dual d1, dual d2
  4  );

D D
- -
X X
于 2012-09-03T09:59:00.800 回答