1

在 1_products t2 我还有其他名为 make,model 的列

当我添加它们时

(SELECT 
            t2.code,t2.make,t2.model
        FROM .....

我明白了

错误 1241 操作数应包含 1 列

SELECT 
    t1.fk_products_id,
    (SELECT 
            t2.code
        FROM
            1_products t2
        WHERE
            t2.id = t1.fk_products_id
        order by code
        limit 1)
FROM
    1_stock t1
WHERE
    t1.branch = 1 and t1.dispatch <> 0;
4

1 回答 1

2

在内联查询中不能返回多于一列。如果要为每列返回多于一列,t1.fk_products_id则必须重写类似于以下的查询:

SELECT t1.fk_products_id,
  t2.code,
  t2.make,
  t2.model
FROM 1_stock t1
LEFT JOIN 1_products t2
  on t1.fk_products_id = t2.id
WHERE t1.branch = 1 
  and t1.dispatch <> 0;
于 2012-11-20T16:51:08.687 回答