Oracle query returns 4 duplicates of each row

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

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 is not working properly?

+3
source share
1 answer

You have a cross 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
+5
source

Source: https://habr.com/ru/post/1749983/


All Articles