Table_1
和Table_2
都有id
和name
列
此查询有效:
SELECT *
FROM (SELECT ROW_NUMBER() OVER() AS rn Table_1.*,
Table_2.*
FROM Table_1
LEFT OUTER JOIN Table_2 on Table_1.id = Table_2.id
)
WHERE rn Between 1 AND 10
但是如何在Table_1中选择列名?我用Table_1.name替换了*,它显示:
SQL0206N "Table_1.name" is not valid in the context where it is used.
SQLSTATE=42703
答案 0 :(得分:3)
您似乎错过了rn
和Table_1
之间的逗号。我认为这应该有效:
SELECT * FROM (
SELECT
ROW_NUMBER() OVER() AS rn
,Table_1.*
,Table_2.*
FROM Table_1
LEFT JOIN Table_2
on Table_1.id = Table_2.id
) A
WHERE rn Between 1 AND 10
答案 1 :(得分:0)
正如bhamby所说,看起来你在rn
和Table_1
您也可以简化查询...
SELECT x.*, y.*
FROM Table_1 x
LEFT JOIN Table_2 y
on x.id = y.id
FETCH FIRST 10 ROWS ONLY