I have a SQL statement that I want to return 6 fields found from a MINUS statement that only compares 1 field from 2 tables. It works properly when the MINUS statement only returns 开发者_JS百科1 entry, but errors if it returns more than 1.
SELECT DROPPER_ID, EMAIL, ACTIVE, COUNTRY_CD, FIRST_NAME, LAST_NAME FROM PETE.DROPPER
WHERE DROPPER_ID = (
SELECT DROPPER_ID FROM PETE.DROPPER WHERE COUNTRY_CD <> 'USA' AND ACTIVE = 1
MINUS
SELECT DROPPER_ID FROM PETE.DROPPER_COMPARE);
How can I accomplish this?
Instead of using =
, try using the IN
statement:
SELECT DROPPER_ID, EMAIL, ACTIVE, COUNTRY_CD, FIRST_NAME, LAST_NAME FROM PETE.DROPPER
WHERE DROPPER_ID IN (
SELECT DROPPER_ID FROM PETE.DROPPER WHERE COUNTRY_CD <> 'USA' AND ACTIVE = 1
MINUS
SELECT DROPPER_ID FROM PETE.DROPPER_COMPARE);
The problem is in your where clause: it is currently designed to compare dropper_id with a single value, but that's not actually what you want. To fix it, replace the '=' symbol with the word 'in'. This will tell the WHERE clause to treat the subquery as a tuple or list of values instead of a single value.
精彩评论