2

This query runs successfully in pgAdmin, but when I transfer it in zend I get:
ERROR: subquery must return only one column...

Can someone distinguish the problem?

  SELECT "trail_history"."new_audit_trail".*,
         (SELECT "admin".list_category_values_new."values"
            FROM "admin".list_category_values_new
           WHERE CAST(seq  AS character varying) = "trail_history"."new_audit_trail"."current_value"
             AND "name" = "trail_history"."new_audit_trail"."name") as "values"
    FROM "trail_history"."new_audit_trail" 
   WHERE (capno LIKE '12101062411001%') 
     AND (recon = '0') 
ORDER BY "date_happened" DESC

1 Answer 1

2

Your sub-select SELECT "admin".list_category_values_new."values"... has nothing that prevents it from returning multiple rows. You need to use TOP 1 or MAX or something to ensure that only one record comes out of the sub-select.

You can correlate the sub-query so that each record in your main select gets a different single value, but if you're going to use a sub-select it can only return one row per row of output in your main select.

Sign up to request clarification or add additional context in comments.

3 Comments

Confusion of terms here. The error is that the subquery should return only one column, but it selecting more than one. However, you are correct .. it can only return one row too with the way it is used here. If the column error is corrected, the row error would be next.
I assumed @OP's question contained a minor error in terminology. Clearly the indicated subquery is only returning one column. The possibility of multiple rows is obviously going to be an issue, however.
@joel-brown Looks like PostgreSQL got the minor error in terminology: it's standart error message.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.