开发者

subquery must return only one column

This query runs successfully in pgAdmin, but when I transfer it in zend I get:

ERROR: subquery must return only one co开发者_如何学JAVAlumn...

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜