简体   繁体   English

子查询中的多个元素

[英]Multiple elements in sub-query

I am trying to write a query in the form of: 我正在尝试以以下形式编写查询:

SELECT
   field_a.table AS x,
   field_b.table AS y,
   ( SELECT
       field_a.tableb AS a,
       field_b.tableb AS b,
    FROM tableb) FROM table

However, I get the following error message: Operand should contain 1 column(s) 但是,我收到以下错误消息:操作数应包含1列

Is there any way this can be done or will I have to resort to multiple sub-queries? 有什么办法可以做到,还是我不得不诉诸多个子查询? I just see it as quite inefficient. 我只是认为它效率很低。

Cheers 干杯

For your proposed query to make any sense at all, it must be the case that table tableb has only one row. 为了使您提出的查询完全没有意义,表tableb仅具有一行。 In that case, you can probably achieve your objective with a join instead of a subquery. 在这种情况下,您可以使用联接而不是子查询来实现目标。 Maybe this is what you want: 也许这就是您想要的:

SELECT
  table.field_a AS x,
  table.field_b AS y,
  tableb.field_a AS a,
  tableb.field_b AS b
FROM
  table CROSS JOIN tableb

If in fact tableb has multiple rows, each correlated in some way with exactly one row of table , then you would instead perform an [INNER] JOIN using a join predicate corresponding to the appropriate relationship. 如果实际上tableb有多行,每行都以某种方式与table某一行相关联,那么您可以使用对应于适当关系的连接谓词执行[INNER] JOIN If you want anything more specific then you'll need to describe your data better. 如果您需要更具体的信息,则需要更好地描述数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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