I’m having issues getting my results properly limited in a query. I have a table of users, with fields like username, password, first/last name, etc. The primary key in this field is the user_id. I also have a table of banned users, which also has a primary key of user_id. My query ideally shows all of the user data and then shows their “Ban status”, based on whether or not their user_id shows up in the ‘Banned Users’ table. The query I currently have in place for this is as follows:
select APEX_ITEM.CHECKBOX(1,gs_users.user_id) checkbox,
"GS_USERS"."USERNAME" as "USERNAME",
"GS_USERS"."FIRST_NAME" as "FIRST_NAME",
"GS_USERS"."LAST_NAME" as "LAST_NAME",
"GS_USERS"."ADMIN_FLAG" as "ADMIN",
"GS_USERS"."EMAIL" as "EMAIL",
CASE
WHEN "GS_USERS"."USER_ID" = "GS_BANNED_USERS"."USER_ID" then 'Banned'
else 'Unbanned'
END status
from
"GS_USERS" "GS_USERS",
"GS_BANNED_USERS" "GS_BANNED_USERS"
Unfortunately, this results in numerous duplicate values. In past situations, I was able to get my unique results using ROWID, but I’m not sure how to work this when the custom column in the case statement. Is there a way I can get the results I’m after?
There is no WHERE clause, so you’re doing a cartesian product between the two tables.
Try this outer join: