我正在运行Oracle查询。它似乎工作,除了它返回每个结果的4个重复。这是查询:
Select * from (
Select a.*, rownum rnum From (
SELECT NEW_USER.*, NEW_EHS_QUIZ_COMPLETE.datetime
FROM NEW_USER, NEW_EHS_QUIZ_COMPLETE
WHERE EXISTS (
select *
from NEW_EHS_QUIZ_COMPLETE
where NEW_USER.id=NEW_EHS_QUIZ_COMPLETE.USER_ID
)
ORDER by last_name ASC
) a
where rownum <= #pgtop#
)
where rnum >= #pgbot#
有谁知道为什么这不能正常工作?
答案 0 :(得分:5)
你在这里有一个交叉联接:
SELECT
NEW_USER.*,
NEW_EHS_QUIZ_COMPLETE.datetime
FROM NEW_USER, NEW_EHS_QUIZ_COMPLETE
WHERE EXISTS(
select * from NEW_EHS_QUIZ_COMPLETE
where NEW_USER.id=NEW_EHS_QUIZ_COMPLETE.USER_ID
)
你可能是这个意思:
SELECT
NEW_USER.*,
NEW_EHS_QUIZ_COMPLETE.datetime
FROM NEW_USER
INNER JOIN NEW_EHS_QUIZ_COMPLETE
ON NEW_USER.id = NEW_EHS_QUIZ_COMPLETE.USER_ID