简体   繁体   中英

How to fix Ora-01427 single-row subquery returns more than one row error?

I have query like this and it gives me single-row subquery returns more than one row error:


SELECT COUNT(PERSONNEL_ID) 
FROM (SELECT DISTINCT * FROM CUSTOMERS)
WHERE CUSTOMER_ID = (SELECT CUSTOMER_ID FROM TRANSACTIONS)

Which tries to get count of distinct PERSONNEL_ID from customers table where CUSTOMER_ID at customers table and CUSTOMER_ID at transactions table are equal

Can you tell me how to fix my query?

You have more than one customer in transactions . Presumably, you intend:

WHERE CUSTOMER_ID IN (SELECT CUSTOMER_ID FROM TRANSACTIONS)

Which you can also phrase as:

WHERE CUSTOMER_ID = ANY (SELECT CUSTOMER_ID FROM TRANSACTIONS)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM