0
SELECT name from SUPPLIER
WHERE code =
(SELECT code FROM STOCK GROUP BY code HAVING COUNT(DISTINCT code)>=3);

I am using SQLPLUS. When the query returns a single result I get the answer I am looking for. However, when it returns more than one row I get this error message:

ORA-01427: single-row subquery returns more than one row

4

2 回答 2

0

there are two possibilities: one thing is to repair the sub-query so that it would always return only one row, other possibility is to use IN or ANY :

SELECT name from SUPPLIER
WHERE code in (SELECT code FROM STOCK GROUP BY code HAVING COUNT(DISTINCT code)>=3);
于 2012-11-24T19:49:27.100 回答
0

In your subquery for a single row operation, multiple rows are being returned which won't be true (i.e = can only compare one value).

Using the group by keyword, multiple rows are being returned and that's why the error will occur.

The solution is to use IN.

于 2013-03-03T17:54:12.040 回答