开发者

oracle query returns 4 duplicates of each row

开发者 https://www.devze.com 2023-01-03 15:49 出处:网络
I am running an Oracle query. It seems to work except that it returns 4 duplicates of each result. Here is the query:

I am running an Oracle query. It seems to work except that it returns 4 duplicates of each result. Here is the query:

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#

Does anyone know why this isn't working properly?


You have a cross join here:

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
) 

You probably mean this:

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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号